List of usage examples for org.jfree.data.general CombinedDataset CombinedDataset
public CombinedDataset()
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Displays an XY chart that is periodically updated by a background thread. This is to * demonstrate the event notification system that automatically updates charts as required. * * @return a chart./* ww w. j a v a 2s. co m*/ */ public JFreeChart createCombinedAndOverlaidDynamicXYChart() { // chart title and axis labels... final String title = this.resources.getString("combined.dynamic.title"); final String subtitleStr = this.resources.getString("combined.dynamic.subtitle"); final String domainAxisLabel = this.resources.getString("combined.dynamic.domain"); final String[] ranges = this.resources.getStringArray("combined.dynamic.ranges"); // setup sample base 2-series dataset final SampleXYDataset data = new SampleXYDataset(); // create some SubSeriesDatasets and CombinedDatasets to test events final XYDataset series0 = new SubSeriesDataset(data, 0); final XYDataset series1 = new SubSeriesDataset(data, 1); final CombinedDataset combinedData = new CombinedDataset(); combinedData.add(series0); combinedData.add(series1); // create common time axis final NumberAxis timeAxis = new NumberAxis(domainAxisLabel); timeAxis.setTickMarksVisible(true); timeAxis.setAutoRangeIncludesZero(false); // make one vertical axis for each (vertical) chart final NumberAxis[] valueAxis = new NumberAxis[4]; for (int i = 0; i < valueAxis.length; i++) { valueAxis[i] = new NumberAxis(ranges[i]); valueAxis[i].setAutoRangeIncludesZero(false); } final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(timeAxis); // add subplot1... final XYItemRenderer renderer0 = new StandardXYItemRenderer(); final XYPlot subplot0 = new XYPlot(series0, null, valueAxis[0], renderer0); plot.add(subplot0, 1); // add subplot2... final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final XYPlot subplot1 = new XYPlot(series1, null, valueAxis[1], renderer1); plot.add(subplot1, 1); // add subplot3... final XYPlot subplot2 = new XYPlot(series0, null, valueAxis[2], new StandardXYItemRenderer()); subplot2.setDataset(1, series1); subplot2.setRenderer(1, new StandardXYItemRenderer()); plot.add(subplot2, 1); // add subplot4... final XYItemRenderer renderer3 = new StandardXYItemRenderer(); final XYPlot subplot3 = new XYPlot(data, null, valueAxis[3], renderer3); plot.add(subplot3, 1); final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); // then customise it a little... final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12)); chart.addSubtitle(subtitle); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.cyan)); // setup thread to update base Dataset final SampleXYDatasetThread update = new SampleXYDatasetThread(data); final Thread thread = new Thread(update); thread.start(); return chart; }