List of usage examples for org.jfree.chart JFreeChart addSubtitle
public void addSubtitle(Title subtitle)
From source file:edu.ucla.stat.SOCR.chart.demo.SpiderWebChartDemo1.java
/** * Creates a sample chart.//from w w w. j a v a 2 s .co m * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { // get a reference to the plot for further customisation... SOCRSpiderWebPlot plot = new SOCRSpiderWebPlot(dataset); JFreeChart chart = new JFreeChart(chartTitle, TextTitle.DEFAULT_FONT, plot, false); LegendTitle legend = new LegendTitle(plot); legend.setPosition(RectangleEdge.BOTTOM); //renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); chart.addSubtitle(legend); setCategorySummary(dataset); if (legendPanelOn) chart.removeLegend(); return chart; }
From source file:org.jfree.chart.demo.MultipleAxisDemo1.java
/** * Creates the demo chart.//ww w. j ava2 s.co m * * @return The chart. */ private JFreeChart createChart() { final XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 1", "Time of Day", "Primary Range Axis", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); chart.addSubtitle(new TextTitle("Four datasets and four range axes.")); final XYPlot plot = chart.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); renderer.setPaint(Color.black); // AXIS 2 final NumberAxis axis2 = new NumberAxis("Range Axis 2"); axis2.setAutoRangeIncludesZero(false); axis2.setLabelPaint(Color.red); axis2.setTickLabelPaint(Color.red); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT); final XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); XYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, Color.red); plot.setRenderer(1, renderer2); // AXIS 3 final NumberAxis axis3 = new NumberAxis("Range Axis 3"); axis3.setLabelPaint(Color.blue); axis3.setTickLabelPaint(Color.blue); plot.setRangeAxis(2, axis3); final XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(), 170); plot.setDataset(2, dataset3); plot.mapDatasetToRangeAxis(2, 2); XYItemRenderer renderer3 = new StandardXYItemRenderer(); renderer3.setSeriesPaint(0, Color.blue); plot.setRenderer(2, renderer3); // AXIS 4 final NumberAxis axis4 = new NumberAxis("Range Axis 4"); axis4.setLabelPaint(Color.green); axis4.setTickLabelPaint(Color.green); plot.setRangeAxis(3, axis4); final XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200); plot.setDataset(3, dataset4); plot.mapDatasetToRangeAxis(3, 3); XYItemRenderer renderer4 = new StandardXYItemRenderer(); renderer4.setSeriesPaint(0, Color.green); plot.setRenderer(3, renderer4); return chart; }
From source file:no.imr.sea2data.guibase.chart.XYBarChart.java
public XYBarChart() { dataset = new XYSeriesCollection(new XYSeries("Series 1")); JFreeChart chart = ChartFactory.createXYBarChart("", "X axis", false, "Y axis", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.white); chart.getTitle().setPaint(Color.black); chart.getTitle().setFont(new Font("SansSerif", Font.PLAIN, 12)); chart.addSubtitle(trendLegend); chart.addSubtitle(trendLegend2);/* www .ja v a2s . c o m*/ trendLegend.setPosition(RectangleEdge.TOP); trendLegend2.setPosition(RectangleEdge.TOP); plot = (XYPlot) chart.getPlot(); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setShadowVisible(false); chartPanel = new ChartPanel(chart); plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); }
From source file:crossspectrumapp.CrossSpectrumApp.java
private void plotData(double[] frequency, double[] power, double[] phase, String title, String subTitleText1, String subTitleText2) throws WebUtilException { XYSeries asdSeries = new XYSeries("asd"); XYSeries phiSeries = new XYSeries("phase"); for (int i = 1; i < frequency.length; i++) { double f = frequency[i]; double pwr = power[i]; double phi = phase[i]; asdSeries.add(f, pwr);/*from w w w.j av a 2 s . c o m*/ phiSeries.add(f, phi); } XYSeriesCollection asdCollection = new XYSeriesCollection(); asdCollection.addSeries(asdSeries); XYSeriesCollection phiCollection = new XYSeriesCollection(); phiCollection.addSeries(phiSeries); // create the chart XYItemRenderer asdRenderer = new StandardXYItemRenderer(); LogAxis asdAxis = new LogAxis("ASD counts/ \u221AHz"); XYPlot asdSubplot = new XYPlot(asdCollection, null, asdAxis, asdRenderer); asdSubplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); XYItemRenderer phiRenderer = new StandardXYItemRenderer(); NumberAxis phiAxis = new NumberAxis("Phase degrees"); XYPlot phiSubplot = new XYPlot(phiCollection, null, phiAxis, phiRenderer); asdSubplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new LogAxis("Frequency (Hz)")); plot.setGap(10.0); // add the subplots... plot.add(asdSubplot, 2); plot.add(phiSubplot, 1); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); Title subTitle = new TextTitle(subTitleText1); chart.addSubtitle(subTitle); subTitle = new TextTitle(subTitleText2); chart.addSubtitle(subTitle); ChartPanel panel = new ChartPanel(chart, true, true, true, false, true); panel.setPreferredSize(new java.awt.Dimension(cscl.getOutX(), cscl.getOutY())); FileOutputStream fos = null; try { fos = new FileOutputStream(cscl.getOfileName()); ChartUtilities.writeChartAsPNG(fos, chart, cscl.getOutX(), cscl.getOutY()); fos.close(); fos = null; } catch (Exception ex) { throw new WebUtilException("Saving image: " + ex.getClass() + " - " + ex.getLocalizedMessage()); } finally { try { if (fos != null) { fos.close(); } } catch (Exception ex) { throw new WebUtilException("Saving image: " + ex.getClass() + " - " + ex.getLocalizedMessage()); } } }
From source file:playground.yu.utils.charts.DoubleBarChart.java
public void saveAsPng(final String filename, final String title, final int width, final int height) { for (int i = 0; i < subCharts.length; i++) plot.add((CategoryPlot) subCharts[i].getChart().getPlot(), 1); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); // add MATSim logo Image image = MatsimResource.getAsImage("matsim_logo_transparent_small.png"); Title subtitle = new ImageTitle(image, RectangleEdge.BOTTOM, HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM);//from w ww .j av a2 s. co m chart.addSubtitle(subtitle); // add default Formatting chart.setBackgroundPaint(new Color(1.0f, 1.0f, 1.0f, 1.0f)); chart.getLegend().setBorder(0.0, 0.0, 0.0, 0.0); try { ChartUtilities.saveChartAsPNG(new File(filename), chart, width, height, null, true, 9); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.polivoto.vistas.acciones.Datos.java
private JFreeChart createChartBar(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart("Votacion", "Opciones", "Total de votos", dataset, PlotOrientation.VERTICAL, true, true, true); try {// ww w . j a va2s. c o m chart.addSubtitle(new TextTitle(ac.getPreguntas().getJSONObject(pox).getString("pregunta"))); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.white)); CategoryPlot plot = chart.getCategoryPlot(); org.jfree.chart.axis.CategoryAxis axis = plot.getDomainAxis(); axis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D)); // final CategoryItemRenderer itemRenderer = new CustomRenderer( // new Paint[] {Color.green, Color.red, Color.blue, Color.yellow, Color.magenta, Color.cyan, Color.pink, Color.lightGray} // ); //// itemRenderer.setBaseItemLabelsVisible(true); //// BarRenderer barRenderer = (BarRenderer)itemRenderer; //// barRenderer.setItemMargin(0.2D); //// plot.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, new java.awt.Color(147, 60, 45))); //// // StandardCategoryToolTipGenerator toolTipGenerator = new StandardCategoryToolTipGenerator("{0}: {2} %", new DecimalFormat("0")); // // // plot.setNoDataMessage("SIN DATOS!"); // // //// renderer.setLabelGenerator(new StandardCategoryLabelGenerator()); // itemRenderer.setItemLabelsVisible(true); // final ItemLabelPosition p = new ItemLabelPosition( // ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0 // ); // itemRenderer.setPositiveItemLabelPosition(p); // plot.setRenderer(itemRenderer); // change the margin at the top of the range axis... final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerMargin(0.15); rangeAxis.setUpperMargin(0.15); } catch (JSONException ex) { Logger.getLogger(Datos.class.getName()).log(Level.SEVERE, null, ex); } return chart; }
From source file:ubic.gemma.visualization.ExpressionDataMatrixVisualizationServiceImpl.java
@Override @Deprecated//from w w w . jav a 2 s .c o m public JFreeChart createXYLineChart(String title, Collection<double[]> dataCol, int numProfiles) { if (dataCol == null) throw new RuntimeException("dataCol cannot be " + null); if (dataCol.size() < numProfiles) { log.info("Collection smaller than number of elements. Will display first " + NUM_PROFILES_TO_DISPLAY + " profiles."); numProfiles = NUM_PROFILES_TO_DISPLAY; } XYSeriesCollection xySeriesCollection = new XYSeriesCollection(); Iterator<double[]> iter = dataCol.iterator(); for (int j = 0; j < numProfiles; j++) { double[] data = iter.next(); XYSeries series = new XYSeries(j, true, true); for (int i = 0; i < data.length; i++) { series.add(i, data[i]); } xySeriesCollection.addSeries(series); } JFreeChart chart = ChartFactory.createXYLineChart(title, "Platform", "Expression Value", xySeriesCollection, PlotOrientation.VERTICAL, false, false, false); chart.addSubtitle(new TextTitle("(Raw data values)", new Font("SansSerif", Font.BOLD, 14))); return chart; }
From source file:compecon.dashboard.panel.IndustriesPanel.java
protected ChartPanel createProductionPanel(Currency currency, GoodType outputGoodType) { TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(); timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry() .getNationalEconomyModel(currency).getIndustryModel(outputGoodType).outputModel.getTimeSeries()); for (GoodType inputGoodType : ApplicationContext.getInstance().getModelRegistry() .getNationalEconomyModel(currency).getIndustryModel(outputGoodType).inputModels.keySet()) { timeSeriesCollection// ww w . j av a2 s . co m .addSeries(ApplicationContext.getInstance().getModelRegistry().getNationalEconomyModel(currency) .getIndustryModel(outputGoodType).inputModels.get(inputGoodType).getTimeSeries()); } JFreeChart chart = ChartFactory.createTimeSeriesChart(outputGoodType.toString() + " Production", "Date", "Output", (XYDataset) timeSeriesCollection, true, true, false); configureChart(chart); chart.addSubtitle(new TextTitle("Inputs: " + ApplicationContext.getInstance().getInputOutputModel() .getProductionFunction(outputGoodType).getInputGoodTypes().toString())); return new ChartPanel(chart); }
From source file:ch.unibe.iam.scg.archie.controller.ProviderChartFactory.java
/** * @param parent/*from w w w .j av a 2 s .c o m*/ * @return Composite with a Chart */ private Composite createPieChart(Composite parent) { // create the dataset... DataSet dataset = this.model.getDataSet(); DefaultPieDataset pieDataset = this.createJFreePieDataset(dataset); // create the chart... JFreeChart chart = this.createJFreePieChart(pieDataset); // add subtitles TextTitle subtitle = new TextTitle(dataset.getHeadings().get(this.model.getValuesIndex()) + " per " + dataset.getHeadings().get(this.model.getKeysIndex())); chart.addSubtitle(subtitle); ChartComposite chartComposite = new ChartComposite(parent, SWT.NONE, chart); chartComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); return chartComposite; }
From source file:org.jfree.chart.demo.ParetoChartDemo.java
/** * Creates a new demo instance./*from w ww . j a va2 s.co m*/ * * @param title the frame title. */ public ParetoChartDemo(final String title) { super(title); final DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("C", new Integer(4843)); data.addValue("C++", new Integer(2098)); data.addValue("C#", new Integer(26)); data.addValue("Java", new Integer(1901)); data.addValue("Perl", new Integer(2507)); data.addValue("PHP", new Integer(1689)); data.addValue("Python", new Integer(948)); data.addValue("Ruby", new Integer(100)); data.addValue("SQL", new Integer(263)); data.addValue("Unix Shell", new Integer(485)); data.sortByValues(SortOrder.DESCENDING); final KeyedValues cumulative = DataUtilities.getCumulativePercentages(data); final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Languages", data); // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Freshmeat Software Projects", // chart title "Language", // domain axis label "Projects", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.addSubtitle(new TextTitle("By Programming Language")); chart.addSubtitle(new TextTitle("As at 5 March 2003")); // set the background color for the chart... chart.setBackgroundPaint(new Color(0xBBBBDD)); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); final CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative", cumulative); final NumberAxis axis2 = new NumberAxis("Percent"); axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.mapDatasetToRangeAxis(1, 1); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); // OPTIONAL CUSTOMISATION COMPLETED. // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(550, 270)); setContentPane(chartPanel); }