Java Code Examples for org.jfree.chart.plot.XYPlot#setDataset()

The following examples show how to use org.jfree.chart.plot.XYPlot#setDataset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeSeriesChartTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    XYSeries series1 = new XYSeries("Series 1");
    series1.add(10.0, 10.0);
    series1.add(20.0, 20.0);
    series1.add(30.0, 30.0);
    XYDataset dataset = new XYSeriesCollection(series1);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setDataset(dataset);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around 10: "
               + range.getLowerBound(), range.getLowerBound() <= 10);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example 2
Source File: XYLineChartTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
public void testReplaceDataset() {

    // create a dataset...
    XYSeries series1 = new XYSeries("Series 1");
    series1.add(10.0, 10.0);
    series1.add(20.0, 20.0);
    series1.add(30.0, 30.0);
    XYDataset dataset = new XYSeriesCollection(series1);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setDataset(dataset);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around 10: "
               + range.getLowerBound(), range.getLowerBound() <= 10);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example 3
Source File: XYLineChartTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    XYSeries series1 = new XYSeries("Series 1");
    series1.add(10.0, 10.0);
    series1.add(20.0, 20.0);
    series1.add(30.0, 30.0);
    XYDataset dataset = new XYSeriesCollection(series1);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setDataset(dataset);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around 10: "
               + range.getLowerBound(), range.getLowerBound() <= 10);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example 4
Source File: ScatterPlotTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    XYSeries series1 = new XYSeries("Series 1");
    series1.add(10.0, 10.0);
    series1.add(20.0, 20.0);
    series1.add(30.0, 30.0);
    XYDataset dataset = new XYSeriesCollection(series1);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setDataset(dataset);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around 10: "
               + range.getLowerBound(), range.getLowerBound() <= 10);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example 5
Source File: XYBarChartTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
public void testReplaceDataset() {

    // create a dataset...
    XYSeries series1 = new XYSeries("Series 1");
    series1.add(10.0, 10.0);
    series1.add(20.0, 20.0);
    series1.add(30.0, 30.0);
    XYDataset dataset = new XYSeriesCollection(series1);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    
    XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setDataset(dataset);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around 10: "
               + range.getLowerBound(), range.getLowerBound() <= 10);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example 6
Source File: XYStepAreaChartTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    XYSeries series1 = new XYSeries("Series 1");
    series1.add(10.0, 10.0);
    series1.add(20.0, 20.0);
    series1.add(30.0, 30.0);
    XYDataset dataset = new XYSeriesCollection(series1);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setDataset(dataset);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around 10: "
               + range.getLowerBound(), range.getLowerBound() <= 10);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example 7
Source File: Chart.java    From Neural-Network-Programming-with-Java-SecondEdition with MIT License 6 votes vote down vote up
/**
 * Performing scatter plot with grid
 * @param xLabel
 * @param yLabel
 */
public JFreeChart scatterGridPlot(String xLabel, String yLabel){
    int numDatasets = dataset.size();
    JFreeChart result = ChartFactory.createScatterPlot(chartTitle
            , xLabel
            , yLabel
            , dataset.get(0));
    XYPlot plot = result.getXYPlot();
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesPaint(0, seriesColor.get(0));        
    for(int i=1;i<numDatasets;i++){
        plot.setDataset(i,dataset.get(i));
        //XYItemRenderer renderer = plot.getRenderer(i-0);
        plot.setRenderer(i, new XYLineAndShapeRenderer(true, true));
        plot.getRenderer(i).setSeriesStroke(0, new BasicStroke(1.0f));
        plot.getRenderer(i).setSeriesPaint(0,seriesColor.get(i));
    }

    return result;
}
 
Example 8
Source File: ScatterPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
public void testReplaceDataset() {

    // create a dataset...
    XYSeries series1 = new XYSeries("Series 1");
    series1.add(10.0, 10.0);
    series1.add(20.0, 20.0);
    series1.add(30.0, 30.0);
    XYDataset dataset = new XYSeriesCollection(series1);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setDataset(dataset);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around 10: "
               + range.getLowerBound(), range.getLowerBound() <= 10);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example 9
Source File: JFreeChartPlotEngine.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
private void pushDataAndRendererIntoPlot(XYPlot plot, int rangeAxisIdx, XYItemRenderer renderer, XYDataset dataset)
		throws ChartPlottimeException {
	if (dataset != null && renderer != null) {
		int datasetIdx = plot.getDatasetCount();
		if (datasetIdx > 0 && plot.getDataset(datasetIdx - 1) == null) {
			datasetIdx -= 1;
		}
		// push dataset and renderer into plot
		try {
			plot.setDataset(datasetIdx, dataset); // if Eclipse states that
													 // dataset might not be
													 // initialized, you did
													 // not consider all
													 // possibilities in the
													 // condition block above
		} catch (RuntimeException e) {
			// probably this is because the domain axis contains values less
			// then zero and the scaling is logarithmic.
			// The shitty JFreeChart implementation does not throw a proper
			// exception stating what happened,
			// but just a RuntimeException with a string, so this is our
			// best guess:
			if (isProbablyZeroValuesOnLogScaleException(e)) {
				throw new ChartPlottimeException("gui.plotter.error.log_axis_contains_zero", "domain axis");
			} else {
				throw e;
			}
		}
		plot.mapDatasetToRangeAxis(datasetIdx, rangeAxisIdx);
		plot.setRenderer(datasetIdx, renderer);
	} else {
		ChartPlottimeException chartPlottimeException = new ChartPlottimeException(
				new PlotConfigurationError("generic_plotter_error"));
		throw chartPlottimeException;
	}
}
 
Example 10
Source File: XYDotRendererTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYDotRenderer r = new XYDotRenderer();
    XYPlot plot = new XYPlot(d1, new NumberAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example 11
Source File: XYBarRendererTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYBarRenderer r = new XYBarRenderer();
    XYPlot plot = new XYPlot(new XYBarDataset(d1, 1.0), new NumberAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, new XYBarDataset(d2, 2.0));
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example 12
Source File: XYLineAndShapeRendererTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);
    
    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYLineAndShapeRenderer r = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot(d1, new NumberAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example 13
Source File: StandardXYItemRendererTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    StandardXYItemRenderer r = new StandardXYItemRenderer();
    XYPlot plot = new XYPlot(d1, new NumberAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example 14
Source File: XYAreaRendererTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYAreaRenderer r = new XYAreaRenderer();
    XYPlot plot = new XYPlot(d1, new NumberAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example 15
Source File: XYPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getLegendItems() method.
 */
public void testGetLegendItems() {
    // check the case where there is a secondary dataset that doesn't 
    // have a renderer (i.e. falls back to renderer 0)
    XYDataset d0 = createDataset1();
    XYDataset d1 = createDataset2();
    XYItemRenderer r0 = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot();
    plot.setDataset(0, d0);
    plot.setDataset(1, d1);
    plot.setRenderer(0, r0);
    LegendItemCollection items = plot.getLegendItems();
    assertEquals(2, items.getItemCount());
}
 
Example 16
Source File: Chart.java    From Neural-Network-Programming-with-Java-SecondEdition with MIT License 5 votes vote down vote up
public JFreeChart scatterPlot(String xAxisLabel,String yAxisLabel){
    int numDatasets = dataset.size();
    JFreeChart result = ChartFactory.createScatterPlot(chartTitle
            , xAxisLabel
            , yAxisLabel
            , dataset.get(0));
    XYPlot plot = result.getXYPlot();
    switch(seriesTypes.get(0)){
            case DOTS:
                plot.setRenderer(0, new XYLineAndShapeRenderer(false, true));
                break;
            case LINES:
                plot.setRenderer(0, new XYLineAndShapeRenderer(true, true));
                break;
        }
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesPaint(0, seriesColor.get(0));        
    for(int i=1;i<numDatasets;i++){
        plot.setDataset(i,dataset.get(i));
        //XYItemRenderer renderer = plot.getRenderer(i-0);
        switch(seriesTypes.get(i)){
            case DOTS:
                plot.setRenderer(i, new XYLineAndShapeRenderer(false, true));
                break;
            case LINES:
                plot.setRenderer(i, new XYLineAndShapeRenderer(true, true));
                break;
        }
        plot.getRenderer(i).setSeriesStroke(0, new BasicStroke(1.0f));
        plot.getRenderer(i).setSeriesPaint(0,seriesColor.get(i));
    }

    return result;
}
 
Example 17
Source File: XYAreaRendererTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYAreaRenderer r = new XYAreaRenderer();
    XYPlot plot = new XYPlot(d1, new NumberAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example 18
Source File: DiagramRenderer.java    From SensorWebClient with GNU General Public License v2.0 4 votes vote down vote up
protected JFreeChart renderPreChart(Map<String, OXFFeatureCollection> entireCollMap, String[] observedProperties,
        ArrayList<TimeSeriesCollection> timeSeries, Calendar begin, Calendar end) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // title
            "Date", // x-axis label
            observedProperties[0], // y-axis label
            timeSeries.get(0), // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
            );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    // add additional datasets:
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setRange(begin.getTime(), end.getTime());
    axis.setDateFormatOverride(new SimpleDateFormat());
    axis.setTimeZone(end.getTimeZone());
    for (int i = 1; i < observedProperties.length; i++) {
        XYDataset additionalDataset = timeSeries.get(i);
        plot.setDataset(i, additionalDataset);
        plot.setRangeAxis(i, new NumberAxis(observedProperties[i]));
        // plot.getRangeAxis(i).setRange((Double)
        // overAllSeriesCollection.getMinimum(i),
        // (Double) overAllSeriesCollection.getMaximum(i));
        plot.mapDatasetToRangeAxis(i, i);
        // plot.getDataset().getXValue(i, i);
    }
    return chart;
}
 
Example 19
Source File: XYBubbleRendererTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
public void testGetLegendItemSeriesIndex() {
    DefaultXYZDataset d1 = new DefaultXYZDataset();
    double[] x = {2.1, 2.3, 2.3, 2.2, 2.2, 1.8, 1.8, 1.9, 2.3, 3.8};
    double[] y = {14.1, 11.1, 10.0, 8.8, 8.7, 8.4, 5.4, 4.1, 4.1, 25};
    double[] z = {2.4, 2.7, 2.7, 2.2, 2.2, 2.2, 2.1, 2.2, 1.6, 4};
    double[][] s1 = new double[][] {x, y, z};
    d1.addSeries("S1", s1);
    x = new double[] {2.1};
    y = new double[] {14.1};
    z = new double[] {2.4};
    double[][] s2 = new double[][] {x, y, z};
    d1.addSeries("S2", s2);

    DefaultXYZDataset d2 = new DefaultXYZDataset();
    x = new double[] {2.1};
    y = new double[] {14.1};
    z = new double[] {2.4};
    double[][] s3 = new double[][] {x, y, z};
    d2.addSeries("S3", s3);
    x = new double[] {2.1};
    y = new double[] {14.1};
    z = new double[] {2.4};
    double[][] s4 = new double[][] {x, y, z};
    d2.addSeries("S4", s4);
    x = new double[] {2.1};
    y = new double[] {14.1};
    z = new double[] {2.4};
    double[][] s5 = new double[][] {x, y, z};
    d2.addSeries("S5", s5);

    XYBubbleRenderer r = new XYBubbleRenderer();
    XYPlot plot = new XYPlot(d1, new NumberAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example 20
Source File: StlPlotter.java    From stl-java with Apache License 2.0 4 votes vote down vote up
private JFreeChart createChart() {

      final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
      final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
      final ClusteredXYBarRenderer barRenderer = new ClusteredXYBarRenderer();
      final GradientPaint black = new GradientPaint(0.0f, 0.0f, Color.black, 0.0f, 0.0f, Color.black);

      final TimeSeries seriests = new TimeSeries("Series");
      final TimeSeries seasonalts = new TimeSeries("Seasonal");
      final TimeSeries trendts = new TimeSeries("Trend");
      final TimeSeries remainderts = new TimeSeries("Remainder");

      final TimeSeries[] tsArray = new TimeSeries[]{seriests, seasonalts, trendts};
      final String[] labels = new String[]{"Series", "Seasonal", "Trend"};

      for (int i = 0; i < series.length; i++) {
        final Date d = new Date((long) times[i]);
        RegularTimePeriod rtp = RegularTimePeriod.createInstance(this.timePeriod, d, TimeZone.getDefault());
        seriests.addOrUpdate(rtp, series[i]);
        seasonalts.addOrUpdate(rtp, seasonal[i]);
        trendts.addOrUpdate(rtp, trend[i]);
        remainderts.addOrUpdate(rtp, remainder[i]);
      }

      plot.setGap(10.0);
      renderer.setSeriesPaint(0, black);
      barRenderer.setSeriesPaint(0, black);
      plot.setOrientation(PlotOrientation.VERTICAL);

      for (int i = 0; i < tsArray.length; i++) {
        final XYDataset ts = new TimeSeriesCollection(tsArray[i]);
        final XYPlot p = new XYPlot(ts, new DateAxis(labels[i]), new NumberAxis(labels[i]), renderer);
        plot.add(p);
      }

      final XYDataset rts = new TimeSeriesCollection(remainderts);
      final XYDataset sts = new TimeSeriesCollection(seriests);
      final XYDataset tts = new TimeSeriesCollection(trendts);
      final XYPlot rplot = new XYPlot(rts, new DateAxis(), new NumberAxis("Remainder"), barRenderer);
      final XYPlot seriesAndTrend = new XYPlot(sts, new DateAxis(), new NumberAxis("S & T"), renderer);

      seriesAndTrend.setDataset(1, tts);
      seriesAndTrend.setRenderer(1, renderer);

      plot.add(rplot);
      plot.add(seriesAndTrend);

      return new JFreeChart(this.title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    }