List of usage examples for org.jfree.chart.title TextTitle TextTitle
public TextTitle(String text)
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample bar chart with just one series. * * @return a sample bar chart./*from w ww . ja va2 s. co m*/ */ public JFreeChart createSingleSeriesBarChart() { // create a default chart based on some sample data... final String title = this.resources.getString("test.single.title"); final String domain = this.resources.getString("test.single.domain"); final String range = this.resources.getString("test.single.range"); final String subtitle1Str = this.resources.getString("test.single.subtitle1"); final String subtitle2Str = this.resources.getString("test.single.subtitle2"); final CategoryDataset data = DemoDatasetFactory.createSingleSeriesCategoryDataset(); final JFreeChart chart = ChartFactory.createBarChart(title, domain, range, data, PlotOrientation.HORIZONTAL, true, true, false); chart.addSubtitle(new TextTitle(subtitle1Str)); chart.addSubtitle(new TextTitle(subtitle2Str)); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.red)); return chart; }
From source file:org.esa.beam.visat.toolviews.stat.ScatterPlotPanel.java
private void computeCoefficientOfDetermination() { int numberOfItems = scatterpointsDataset.getSeries(0).getItemCount(); double arithmeticMeanOfX = 0; //arithmetic mean of X double arithmeticMeanOfY = 0; //arithmetic mean of Y double varX = 0; //variance of X double varY = 0; //variance of Y double coVarXY = 0; //covariance of X and Y; //compute arithmetic means for (int i = 0; i < numberOfItems; i++) { arithmeticMeanOfX += scatterpointsDataset.getXValue(0, i); arithmeticMeanOfY += scatterpointsDataset.getYValue(0, i); }/*from w w w .ja v a 2 s .c o m*/ arithmeticMeanOfX /= numberOfItems; arithmeticMeanOfY /= numberOfItems; //compute variances and covariance for (int i = 0; i < numberOfItems; i++) { varX += Math.pow(scatterpointsDataset.getXValue(0, i) - arithmeticMeanOfX, 2); varY += Math.pow(scatterpointsDataset.getYValue(0, i) - arithmeticMeanOfY, 2); coVarXY += (scatterpointsDataset.getXValue(0, i) - arithmeticMeanOfX) * (scatterpointsDataset.getYValue(0, i) - arithmeticMeanOfY); } //computation of coefficient of determination double r2 = Math.pow(coVarXY, 2) / (varX * varY); r2 = MathUtils.round(r2, Math.pow(10.0, 5)); final double[] coefficients = Regression.getOLSRegression(scatterpointsDataset, 0); final double intercept = coefficients[0]; final double slope = coefficients[1]; final String linearEquation; if (intercept >= 0) { linearEquation = "y = " + (float) slope + "x + " + (float) intercept; } else { linearEquation = "y = " + (float) slope + "x - " + Math.abs((float) intercept); } TextTitle tt = new TextTitle(linearEquation + "\nR = " + r2); tt.setTextAlignment(HorizontalAlignment.RIGHT); tt.setFont(chart.getLegend().getItemFont()); tt.setBackgroundPaint(new Color(200, 200, 255, 100)); tt.setFrame(new BlockBorder(Color.white)); tt.setPosition(RectangleEdge.BOTTOM); r2Annotation = new XYTitleAnnotation(0.98, 0.02, tt, RectangleAnchor.BOTTOM_RIGHT); r2Annotation.setMaxWidth(0.48); getPlot().addAnnotation(r2Annotation); }
From source file:ro.nextreports.engine.chart.JFreeChartExporter.java
private void setTitle(JFreeChart jfreechart) { TextTitle title = new TextTitle(StringUtil.getI18nString(replaceParameters(chart.getTitle().getTitle()), I18nUtil.getLanguageByName(chart, language))); title.setFont(chart.getTitle().getFont()); title.setPaint(chart.getTitle().getColor()); if (chart.getTitle().getAlignment() == ChartTitle.LEFT_ALIGNMENT) { title.setHorizontalAlignment(HorizontalAlignment.LEFT); } else if (chart.getTitle().getAlignment() == ChartTitle.RIGHT_ALIGNMENT) { title.setHorizontalAlignment(HorizontalAlignment.RIGHT); } else {//ww w .j a v a2 s . c o m title.setHorizontalAlignment(HorizontalAlignment.CENTER); } jfreechart.setTitle(title); }
From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java
/** * Create a chart-object using dataset object. This method takes a dataset object, e.g. a DialWidgetDefinition, * and creates and returns a JFreeChart object from it. * //from ww w .j a va 2 s . c om * @param dataset * The dataset * @param title * The title of the chart * @param units * The units of the chart value * @param width * The width of the image to create * @param height * The height of the image to create * @param logger * The logger to log any messages to * * @return JFreeChart the generated chart object */ public static JFreeChart getChart(final Dataset dataset, final String title, final String units, final int width, final int height, final ILogger logger) { JFreeChart chart = null; if (dataset instanceof DialWidgetDefinition) { chart = JFreeChartEngine.createDial((DialWidgetDefinition) dataset, title, units); } else if (dataset instanceof TimeSeriesCollectionChartDefinition) { chart = JFreeChartEngine.createTimeSeriesCollectionChart((TimeSeriesCollectionChartDefinition) dataset); } else if (dataset instanceof TimeTableXYDatasetChartDefinition) { chart = JFreeChartEngine.createStackedTimeSeriesChart((TimeTableXYDatasetChartDefinition) dataset); } else if (dataset instanceof XYSeriesCollectionChartDefinition) { chart = JFreeChartEngine.createXYSeriesCollectionChart((XYSeriesCollectionChartDefinition) dataset); } else if (dataset instanceof BarLineChartDefinition) { chart = JFreeChartEngine.createBarLineChart((BarLineChartDefinition) dataset); } else if (dataset instanceof CategoryDatasetChartDefinition) { chart = JFreeChartEngine.createCategoryDatasetChart((CategoryDatasetChartDefinition) dataset); } else if (dataset instanceof PieDatasetChartDefinition) { chart = JFreeChartEngine.createPieDatasetChart((PieDatasetChartDefinition) dataset); } else if (dataset instanceof XYZSeriesCollectionChartDefinition) { chart = JFreeChartEngine.createXYZSeriesCollectionChart((XYZSeriesCollectionChartDefinition) dataset); } if (chart == null) { logger.error(Messages.getInstance().getString("ChartEngine.ERROR_0002_COULD_NOT_CREATE_CHART")); //$NON-NLS-1$ } else { // TODO implement the ability to have "ImageTitle"s for subtitles ChartDefinition chartDefinition = (ChartDefinition) dataset; Iterator iter = chartDefinition.getSubtitles().iterator(); while (iter.hasNext()) { chart.addSubtitle(new TextTitle(iter.next().toString())); } chart.setBackgroundPaint(chartDefinition.getChartBackgroundPaint()); chart.setBackgroundImage(chartDefinition.getChartBackgroundImage()); chart.setBorderVisible(chartDefinition.isBorderVisible()); chart.setBorderPaint(chartDefinition.getBorderPaint()); if (chart.getTitle() != null) { chart.getTitle().setPosition(chartDefinition.getTitlePosition()); chart.getTitle().setFont(chartDefinition.getTitleFont()); } if (chartDefinition.getLegendFont() != null && chart.getLegend() != null) { chart.getLegend().setItemFont(chartDefinition.getLegendFont()); } if (!chartDefinition.isLegendBorderVisible() && chart.getLegend() != null) { chart.getLegend().setBorder(BlockBorder.NONE); } if (chartDefinition.getLegendPosition() != null && chart.getLegend() != null) { chart.getLegend().setPosition(chartDefinition.getLegendPosition()); } } return (chart); }
From source file:CGgui.java
public void addMinima(double value) { //updata dataset and graph if (value != -1) { //remove previous minima for this number of CGs for (int i = 0; i < minimadataset.getItemCount(); i++) { if (minimadataset.getYValue(0, i) == CurrCG) { minimadataset.remove(minimadataset.getX(0, i), (String) key, true); break; }/* www. ja v a 2s . co m*/ } //add new minima minimadataset.add(value, (double) CurrCG, (String) key); } else return; //get plot XYPlot xyplot = minchart.getXYPlot(); minchart.clearSubtitles(); //set render options XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); Shape shape = xyplot.getRenderer().getSeriesShape(0); renderer1.setSeriesLinesVisible(0, false); renderer1.setSeriesPaint(0, Color.RED); renderer1.setSeriesShape(0, shape); if (minimadataset.getItemCount() > 1) { renderer2.setSeriesLinesVisible(0, true); renderer2.setSeriesShapesVisible(0, false); renderer2.setBaseSeriesVisibleInLegend(false); renderer2.setSeriesPaint(0, Color.BLUE); } //get regression LineFunction2D localregline = null; XYDataset regseries; if (minimadataset.getItemCount() > 1) { //create the regression double[] reg = Regression.getOLSRegression(minimadataset, 0); //looking for x values so put x in terms of y //y = a + bx for local //x = y/b - a/b for global if (DEBUG) PrintText("Regression: y = " + reg[0] + " + " + reg[1] + "x\n"); //global (in terms of y) regLine = new LineFunction2D(-reg[0] / reg[1], 1 / reg[1]); //local (in terms of x) localregline = new LineFunction2D(reg[0], reg[1]); regseries = DatasetUtilities.sampleFunction2D(localregline, minimadataset.getDomainLowerBound(false), minimadataset.getDomainUpperBound(false), 2, "Linear Regression"); //plot line xyplot.setDataset(1, regseries); xyplot.setRenderer(1, renderer2); minchart.addSubtitle(0, new TextTitle("Regression: y = " + reg[0] + " + " + reg[1] + "x")); } xyplot.setDataset(0, minimadataset); xyplot.setRenderer(0, renderer1); //f.pack(); //System.gc(); }
From source file:cnu.eslab.fileTest.NewJFrame.java
public void PieGraphGenerate(String[] arGrop, double[] arValue, String arTitle, String arSubTitle) { // ?? ?.//from w ww.jav a 2 s . com DefaultPieDataset data = new DefaultPieDataset(); data.setValue(arGrop[0], arValue[0]); //CPU data.setValue(arGrop[1], arValue[1]); //WIFI data.setValue(arGrop[5], arValue[5]); //3G data.setValue(arGrop[2], arValue[2]); //LED data.setValue(arGrop[3], arValue[3]); //GPS data.setValue(arGrop[4], arValue[4]); //AUDIO //offset data . RectangleInsets pieOffset = new RectangleInsets(50.0, 50.0, 50.0, 50.0); // ? ?. JFreeChart chart = ChartFactory.createPieChart(arTitle, data, true, true, false); TextTitle subTitle = new TextTitle(arSubTitle); chart.setBackgroundPaint(Color.WHITE); chart.addSubtitle(subTitle); PiePlot pieplot = (PiePlot) chart.getPlot(); pieplot.setNoDataMessage("No data available"); pieplot.setExplodePercent("LED", 0.20000000000000001D); pieplot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1} mW) ({2} percent)")); pieplot.setLabelBackgroundPaint(new Color(220, 220, 220)); pieplot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}")); //? /*pieplot.setSectionPaint(arGrop[0], new Color(0,0,0)); pieplot.setSectionPaint(arGrop[1], new Color(60,60,60)); pieplot.setSectionPaint(arGrop[2], new Color(120,120,120)); pieplot.setSectionPaint(arGrop[4], new Color(180,180,180));*/ //pieplot.setSimpleLabels(true); //pieplot.setSimpleLabelOffset(pieOffset); //?? offset? . pieplot.setInteriorGap(0.0D); // ?? ?. ChartPanel chartPanel = new ChartPanel(chart); JFrame f = new JFrame(""); f.setSize(600, 600); f.getContentPane().add(chartPanel); // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:cnu.eslab.fileTest.NewJFrame.java
public void LineGraphGenerate(ArrayList<Integer> arList, String arTitle, String arSubTitle, String arLineName) { // ??? ?? .// ww w .j a v a 2s .c o m XYSeries series = new XYSeries(arLineName); for (int i = 0; i < arList.size(); i++) { // ? ? . series.add(i, arList.get(i)); } // ? . XYDataset dataset = new XYSeriesCollection(series); // ? ?. JFreeChart chart = ChartFactory.createXYLineChart(arTitle, "Time(sec)", "Power(mW)", dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, true, false); TextTitle subTitle = new TextTitle(arSubTitle); chart.setBackgroundPaint(Color.WHITE); chart.addSubtitle(subTitle); ChartPanel chartPanel = new ChartPanel(chart); JFrame f = new JFrame("Power consumption chart"); f.setSize(600, 600); f.getContentPane().add(chartPanel); // ? ? ? close ? . // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
protected void setChartSubtitles(JFreeChart jfreeChart, Integer baseFontSize) throws JRException { Boolean subtitleVisibility = (Boolean) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_VISIBLE); if (subtitleVisibility != null && subtitleVisibility.booleanValue()) { String subtitleText = (String) evaluateExpression(getChart().getSubtitleExpression()); if (subtitleText != null) { TextTitle subtitle = new TextTitle(subtitleText); Font themeSubtitleFont = getFont( (JRFont) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_FONT), getChart().getSubtitleFont(), baseFontSize); subtitle.setFont(themeSubtitleFont); HorizontalAlignment defaultSubtitleHAlignment = (HorizontalAlignment) getDefaultValue( defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_HORIZONTAL_ALIGNMENT); if (defaultSubtitleHAlignment != null) subtitle.setHorizontalAlignment(defaultSubtitleHAlignment); VerticalAlignment defaultSubtitleVAlignment = (VerticalAlignment) getDefaultValue( defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_VERTICAL_ALIGNMENT); if (defaultSubtitleVAlignment != null) subtitle.setVerticalAlignment(defaultSubtitleVAlignment); RectangleInsets defaultSubtitlePadding = (RectangleInsets) getDefaultValue( defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_PADDING); RectangleInsets subtitlePadding = subtitle.getPadding() != null ? subtitle.getPadding() : defaultSubtitlePadding; if (subtitlePadding != null) subtitle.setPadding(subtitlePadding); Color subtitleForecolor = getChart().getOwnSubtitleColor() != null ? getChart().getOwnSubtitleColor() : (getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_FORECOLOR) != null ? (Color) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_FORECOLOR) : getChart().getSubtitleColor()); if (subtitleForecolor != null) subtitle.setPaint(subtitleForecolor); Color subtitleBackcolor = getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_BACKCOLOR) != null ? (Color) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_BACKCOLOR) : null;/*from w ww . ja v a 2s . c om*/ if (subtitleBackcolor != null) subtitle.setBackgroundPaint(subtitleBackcolor); RectangleEdge defaultSubtitlePosition = (RectangleEdge) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_POSITION); //Subtitle has not its own position set, and by default this will be set the same as title position RectangleEdge subtitleEdge = null; if (defaultSubtitlePosition == null) { subtitleEdge = jfreeChart.getTitle().getPosition(); } else { subtitleEdge = defaultSubtitlePosition; } if (subtitleEdge != null) subtitle.setPosition(subtitleEdge); jfreeChart.addSubtitle(subtitle); } } }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
protected void setChartSubtitles(JFreeChart jfreeChart) throws JRException { TitleSettings subtitleSettings = getSubtitleSettings(); Boolean subtitleVisibility = subtitleSettings.getShowTitle(); if (subtitleVisibility == null || subtitleVisibility.booleanValue()) { String subtitleText = (String) evaluateExpression(getChart().getSubtitleExpression()); if (subtitleText != null) { TextTitle subtitle = new TextTitle(subtitleText); Paint subtitleForecolor = getChart().getOwnSubtitleColor() != null ? getChart().getOwnSubtitleColor() : subtitleSettings.getForegroundPaint() != null ? subtitleSettings.getForegroundPaint().getPaint() : getChart().getSubtitleColor(); //Subtitle has not its own position set, and by default this will be set the same as title position RectangleEdge subtitleEdge = getEdge(subtitleSettings.getPositionValue(), jfreeChart.getTitle() == null ? null : jfreeChart.getTitle().getPosition()); handleTitleSettings(subtitle, subtitleSettings, getChart().getSubtitleFont(), subtitleForecolor, subtitleEdge);//from w w w. jav a 2 s.com jfreeChart.addSubtitle(subtitle); } } }
From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java
protected void setChartSubtitles(JFreeChart jfreeChart, Integer baseFontSize) throws JRException { Boolean subtitleVisibility = (Boolean) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_VISIBLE); if (subtitleVisibility != null && subtitleVisibility) { String subtitleText = evaluateTextExpression(getChart().getSubtitleExpression()); if (subtitleText != null) { TextTitle subtitle = new TextTitle(subtitleText); Font themeSubtitleFont = getFont( (JRFont) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_FONT), getChart().getSubtitleFont(), baseFontSize); subtitle.setFont(themeSubtitleFont); HorizontalAlignment defaultSubtitleHAlignment = (HorizontalAlignment) getDefaultValue( defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_HORIZONTAL_ALIGNMENT); if (defaultSubtitleHAlignment != null) subtitle.setHorizontalAlignment(defaultSubtitleHAlignment); VerticalAlignment defaultSubtitleVAlignment = (VerticalAlignment) getDefaultValue( defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_VERTICAL_ALIGNMENT); if (defaultSubtitleVAlignment != null) subtitle.setVerticalAlignment(defaultSubtitleVAlignment); RectangleInsets defaultSubtitlePadding = (RectangleInsets) getDefaultValue( defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_PADDING); RectangleInsets subtitlePadding = subtitle.getPadding() != null ? subtitle.getPadding() : defaultSubtitlePadding; if (subtitlePadding != null) subtitle.setPadding(subtitlePadding); Color subtitleForecolor = getChart().getOwnSubtitleColor() != null ? getChart().getOwnSubtitleColor() : (getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_FORECOLOR) != null ? (Color) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_FORECOLOR) : getChart().getSubtitleColor()); if (subtitleForecolor != null) subtitle.setPaint(subtitleForecolor); Color subtitleBackcolor = getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_BACKCOLOR) != null ? (Color) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_BACKCOLOR) : null;//from www . j a va 2 s .c o m if (subtitleBackcolor != null) subtitle.setBackgroundPaint(subtitleBackcolor); RectangleEdge defaultSubtitlePosition = (RectangleEdge) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_POSITION); //Subtitle has not its own position set, and by default this will be set the same as title position RectangleEdge subtitleEdge = null; if (defaultSubtitlePosition == null) { subtitleEdge = jfreeChart.getTitle().getPosition(); } else { subtitleEdge = defaultSubtitlePosition; } if (subtitleEdge != null) subtitle.setPosition(subtitleEdge); jfreeChart.addSubtitle(subtitle); } } }