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

The following examples show how to use org.jfree.chart.plot.CategoryPlot#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: LineChart3DTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the chart's dataset and then checks that the new dataset is OK.
 */
public void testReplaceDataset() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
            "C", data);

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

}
 
Example 2
Source File: CategoryStepRendererTest.java    From ECG-Viewer with GNU General Public License v2.0 6 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() {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(23.0, "R3", "C1");
    dataset1.addValue(24.0, "R4", "C1");
    dataset1.addValue(25.0, "R5", "C1");
    CategoryStepRenderer r = new CategoryStepRenderer();
    CategoryPlot plot = new CategoryPlot(dataset0, new CategoryAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, dataset1);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("R5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example 3
Source File: BarChart3DTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that the data range is as expected.
 */
public void testReplaceDataset() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", 
            "C", data);

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

}
 
Example 4
Source File: LineChartTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the chart's dataset and then checks that the new dataset is OK.
 */
public void testReplaceDataset() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
            "C", data);

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

}
 
Example 5
Source File: AreaRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
public void testGetLegendItemSeriesIndex() {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(23.0, "R3", "C1");
    dataset1.addValue(24.0, "R4", "C1");
    dataset1.addValue(25.0, "R5", "C1");
    AreaRenderer r = new AreaRenderer();
    CategoryPlot plot = new CategoryPlot(dataset0, new CategoryAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, dataset1);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("R5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example 6
Source File: NumberAxisTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * A simple test for the auto-range calculation looking at a
 * NumberAxis used as the range axis for a CategoryPlot.  In this
 * case, the 'autoRangeIncludesZero' flag is set to false AND the
 * original dataset is replaced with a new dataset.
 */
@Test
public void testAutoRange3() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(100.0, "Row 1", "Column 1");
    dataset.setValue(200.0, "Row 1", "Column 2");
    JFreeChart chart = ChartFactory.createLineChart("Test", "Categories",
            "Value", dataset, PlotOrientation.VERTICAL, false, false,
            false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRangeIncludesZero(false);
    assertEquals(axis.getLowerBound(), 95.0, EPSILON);
    assertEquals(axis.getUpperBound(), 205.0, EPSILON);

    // now replacing the dataset should update the axis range...
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(900.0, "Row 1", "Column 1");
    dataset2.setValue(1000.0, "Row 1", "Column 2");
    plot.setDataset(dataset2);
    assertEquals(axis.getLowerBound(), 895.0, EPSILON);
    assertEquals(axis.getUpperBound(), 1005.0, EPSILON);
}
 
Example 7
Source File: BarChartTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Replaces the chart's dataset and then checks that the new dataset is OK.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
            "C", data);

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

}
 
Example 8
Source File: ChartJFreeChartOutputHistogram.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void clearDataSet(final IScope scope) {
	// TODO Auto-generated method stub
	super.clearDataSet(scope);
	final CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
	for (int i = plot.getDatasetCount() - 1; i >= 1; i--) {
		plot.setDataset(i, null);
		plot.setRenderer(i, null);
	}
	((DefaultCategoryDataset) jfreedataset.get(0)).clear();
	jfreedataset.clear();
	jfreedataset.add(0, new DefaultCategoryDataset());
	plot.setDataset((DefaultCategoryDataset) jfreedataset.get(0));
	plot.setRenderer(0, null);
	IdPosition.clear();
	nbseries = 0;
}
 
Example 9
Source File: StackedBarChartTests.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...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
            "C", data);

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

}
 
Example 10
Source File: AreaRendererTest.java    From ECG-Viewer with GNU General Public License v2.0 6 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() {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(23.0, "R3", "C1");
    dataset1.addValue(24.0, "R4", "C1");
    dataset1.addValue(25.0, "R5", "C1");
    AreaRenderer r = new AreaRenderer();
    CategoryPlot plot = new CategoryPlot(dataset0, new CategoryAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, dataset1);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("R5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example 11
Source File: StackedBarChart3DTest.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...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
            "C", data);

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

}
 
Example 12
Source File: LineChartTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the chart's dataset and then checks that the new dataset is OK.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
            "C", data);

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

}
 
Example 13
Source File: BarChartTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Replaces the chart's dataset and then checks that the new dataset is OK.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
            "C", data);

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

}
 
Example 14
Source File: AreaRendererTest.java    From ccu-historian with GNU General Public License v3.0 6 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() {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(23.0, "R3", "C1");
    dataset1.addValue(24.0, "R4", "C1");
    dataset1.addValue(25.0, "R5", "C1");
    AreaRenderer r = new AreaRenderer();
    CategoryPlot plot = new CategoryPlot(dataset0, new CategoryAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, dataset1);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("R5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example 15
Source File: StackedBarChartTest.java    From SIMVA-SoS with Apache License 2.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...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
            "C", data);

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

}
 
Example 16
Source File: LineAndShapeRendererTest.java    From ECG-Viewer with GNU General Public License v2.0 6 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() {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(23.0, "R3", "C1");
    dataset1.addValue(24.0, "R4", "C1");
    dataset1.addValue(25.0, "R5", "C1");
    LineAndShapeRenderer r = new LineAndShapeRenderer();
    CategoryPlot plot = new CategoryPlot(dataset0, new CategoryAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, dataset1);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("R5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example 17
Source File: AreaChartTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Replaces the chart's dataset and then checks that the new dataset is OK.
 */
@Test
public void testReplaceDataset() {
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset(
            "S", "C", data);
    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    plot.setDataset(newData);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around -30: "
               + range.getLowerBound(), range.getLowerBound() <= -30);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example 18
Source File: GanttChartTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws the chart with a <code>null</code> info object to make sure that
 * no exceptions are thrown (a problem that was occurring at one point).
 */
@Test
public void testDrawWithNullInfo2() {
    JFreeChart chart = createGanttChart();
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDataset(createDataset());
    /* BufferedImage img =*/ chart.createBufferedImage(300, 200, null);
    //FIXME we should really assert a value
}
 
Example 19
Source File: CategoryPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for bug report 1169972.
 */
public void test1169972() {
    CategoryPlot plot = new CategoryPlot(null, null, null, null);
    plot.setDomainAxis(new CategoryAxis("C"));
    plot.setRangeAxis(new NumberAxis("Y"));
    plot.setRenderer(new BarRenderer());
    plot.setDataset(new DefaultCategoryDataset());
    assertTrue(plot != null);
}
 
Example 20
Source File: GanttChartTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Replaces the chart's dataset and then checks that the new dataset is OK.
 */
@Test
public void testReplaceDataset() {
    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    plot.setDataset(null);
    assertEquals(true, l.flag);
}