org.jfree.data.xy.DefaultXYDataset Java Examples

The following examples show how to use org.jfree.data.xy.DefaultXYDataset. 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: XYPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test for bug 1654215 (where a renderer is added to the plot without
 * a corresponding dataset and it throws an exception at drawing time).
 */
public void test1654215() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(1, new XYLineAndShapeRenderer());
    boolean success = false;
    try {
        BufferedImage image = new BufferedImage(200 , 100, 
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
        success = true;
    }
    catch (Exception e) {
        e.printStackTrace();
        success = false;
    }
    assertTrue(success);
}
 
Example #2
Source File: XYPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test for drawing a plot where a series has zero items.  With
 * JFreeChart 1.0.5+cvs this was throwing an exception at one point.
 */
@Test
public void testDrawSeriesWithZeroItems() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    dataset.addSeries("Series 1", new double[][] {{1.0, 2.0}, {3.0, 4.0}});
    dataset.addSeries("Series 2", new double[][] {{}, {}});
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #3
Source File: XYPlotTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test for drawing range grid lines when there is no primary renderer.
 * In 1.0.4, this is throwing a NullPointerException.
 */
@Test
public void testDrawRangeGridlines() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(null);
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #4
Source File: DefaultXYDatasetTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {

    DefaultXYDataset d1 = new DefaultXYDataset();
    DefaultXYDataset d2 = new DefaultXYDataset();
    assertTrue(d1.equals(d2));
    assertTrue(d2.equals(d1));

    double[] x1 = new double[] {1.0, 2.0, 3.0};
    double[] y1 = new double[] {4.0, 5.0, 6.0};
    double[][] data1 = new double[][] {x1, y1};
    double[] x2 = new double[] {1.0, 2.0, 3.0};
    double[] y2 = new double[] {4.0, 5.0, 6.0};
    double[][] data2 = new double[][] {x2, y2};
    d1.addSeries("S1", data1);
    assertFalse(d1.equals(d2));
    d2.addSeries("S1", data2);
    assertTrue(d1.equals(d2));
}
 
Example #5
Source File: XYPlotTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test for bug 1654215 (where a renderer is added to the plot without
 * a corresponding dataset and it throws an exception at drawing time).
 */
@Test
public void test1654215() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(1, new XYLineAndShapeRenderer());
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #6
Source File: XYPlotTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * A test for drawing a plot where a series has zero items.  With
 * JFreeChart 1.0.5+cvs this was throwing an exception at one point.
 */
@Test
public void testDrawSeriesWithZeroItems() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    dataset.addSeries("Series 1", new double[][] {{1.0, 2.0}, {3.0, 4.0}});
    dataset.addSeries("Series 2", new double[][] {{}, {}});
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #7
Source File: XYPlotTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * A test for drawing range grid lines when there is no primary renderer.
 * In 1.0.4, this is throwing a NullPointerException.
 */
@Test
public void testDrawRangeGridlines() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(null);
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #8
Source File: XYPlotTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * A test for bug 1654215 (where a renderer is added to the plot without
 * a corresponding dataset and it throws an exception at drawing time).
 */
@Test
public void test1654215() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(1, new XYLineAndShapeRenderer());
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #9
Source File: XYSeriesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for an example using the toArray() method.
 */
public void testToArrayExample() {
    XYSeries s = new XYSeries("S");
    s.add(1.0, 11.0);
    s.add(2.0, 22.0);
    s.add(3.5, 35.0);
    s.add(5.0, null);
    DefaultXYDataset dataset = new DefaultXYDataset();
    dataset.addSeries("S", s.toArray());
    assertEquals(1, dataset.getSeriesCount());
    assertEquals(4, dataset.getItemCount(0));
    assertEquals("S", dataset.getSeriesKey(0));
    assertEquals(1.0, dataset.getXValue(0, 0), EPSILON);
    assertEquals(2.0, dataset.getXValue(0, 1), EPSILON);
    assertEquals(3.5, dataset.getXValue(0, 2), EPSILON);
    assertEquals(5.0, dataset.getXValue(0, 3), EPSILON);
    assertEquals(11.0, dataset.getYValue(0, 0), EPSILON);
    assertEquals(22.0, dataset.getYValue(0, 1), EPSILON);
    assertEquals(35.0, dataset.getYValue(0, 2), EPSILON);
    assertTrue(Double.isNaN(dataset.getYValue(0, 3)));
}
 
Example #10
Source File: XYPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test for drawing range grid lines when there is no primary renderer.
 * In 1.0.4, this is throwing a NullPointerException.
 */
@Test
public void testDrawRangeGridlines() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(null);
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #11
Source File: XYPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test for drawing a plot where a series has zero items.  With
 * JFreeChart 1.0.5+cvs this was throwing an exception at one point.
 */
@Test
public void testDrawSeriesWithZeroItems() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    dataset.addSeries("Series 1", new double[][] {{1.0, 2.0}, {3.0, 4.0}});
    dataset.addSeries("Series 2", new double[][] {{}, {}});
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #12
Source File: ChartPanelTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks that a call to the zoom() method generates just one
 * ChartChangeEvent.
 */
public void test2502355_zoom() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X",
            "Y", dataset, false);
    ChartPanel panel = new ChartPanel(chart);
    chart.addChangeListener(this);
    this.chartChangeEvents.clear();
    panel.zoom(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertEquals(1, this.chartChangeEvents.size());
}
 
Example #13
Source File: XYBarDatasetTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    DefaultXYDataset d1 = new DefaultXYDataset();
    double[] x1 = new double[] {1.0, 2.0, 3.0};
    double[] y1 = new double[] {4.0, 5.0, 6.0};
    double[][] data1 = new double[][] {x1, y1};
    d1.addSeries("S1", data1);
    DefaultXYDataset d2 = new DefaultXYDataset();
    double[] x2 = new double[] {1.0, 2.0, 3.0};
    double[] y2 = new double[] {4.0, 5.0, 6.0};
    double[][] data2 = new double[][] {x2, y2};
    d2.addSeries("S1", data2);

    XYBarDataset bd1 = new XYBarDataset(d1, 5.0);
    XYBarDataset bd2 = new XYBarDataset(d2, 5.0);
    assertTrue(bd1.equals(bd2));
    assertTrue(bd2.equals(bd1));
}
 
Example #14
Source File: XYPlotTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test for drawing range grid lines when there is no primary renderer.
 * In 1.0.4, this is throwing a NullPointerException.
 */
@Test
public void testDrawRangeGridlines() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(null);
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #15
Source File: ChartPanelTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks that a call to the zoom() method generates just one
 * ChartChangeEvent.
 */
@Test
public void test2502355_zoom() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X",
            "Y", dataset, PlotOrientation.VERTICAL, false, false, false);
    ChartPanel panel = new ChartPanel(chart);
    chart.addChangeListener(this);
    this.chartChangeEvents.clear();
    panel.zoom(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertEquals(1, this.chartChangeEvents.size());
}
 
Example #16
Source File: DefaultXYDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a sample dataset for testing.
 * 
 * @return A sample dataset.
 */
public DefaultXYDataset createSampleDataset1() {
    DefaultXYDataset d = new DefaultXYDataset();
    double[] x1 = new double[] {1.0, 2.0, 3.0};
    double[] y1 = new double[] {4.0, 5.0, 6.0};
    double[][] data1 = new double[][] {x1, y1};
    d.addSeries("S1", data1);
    
    double[] x2 = new double[] {1.0, 2.0, 3.0};
    double[] y2 = new double[] {4.0, 5.0, 6.0};
    double[][] data2 = new double[][] {x2, y2};
    d.addSeries("S2", data2);
    return d;
}
 
Example #17
Source File: ChartPanelTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that a call to the zoomOutRange() method, for a plot with more
 * than one range axis, generates just one ChartChangeEvent.
 */
@Test
public void test2502355_zoomOutRange() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X",
            "Y", dataset, PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeAxis(1, new NumberAxis("X2"));
    ChartPanel panel = new ChartPanel(chart);
    chart.addChangeListener(this);
    this.chartChangeEvents.clear();
    panel.zoomOutRange(1.0, 2.0);
    assertEquals(1, this.chartChangeEvents.size());
}
 
Example #18
Source File: ChartPanelTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that a call to the zoomOutDomain() method, for a plot with more
 * than one domain axis, generates just one ChartChangeEvent.
 */
@Test
public void test2502355_zoomOutDomain() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X",
            "Y", dataset, PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainAxis(1, new NumberAxis("X2"));
    ChartPanel panel = new ChartPanel(chart);
    chart.addChangeListener(this);
    this.chartChangeEvents.clear();
    panel.zoomOutDomain(1.0, 2.0);
    assertEquals(1, this.chartChangeEvents.size());
}
 
Example #19
Source File: ChartPanelTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that a call to the zoomInRange() method, for a plot with more
 * than one range axis, generates just one ChartChangeEvent.
 */
@Test
public void test2502355_zoomInRange() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X",
            "Y", dataset, PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeAxis(1, new NumberAxis("X2"));
    ChartPanel panel = new ChartPanel(chart);
    chart.addChangeListener(this);
    this.chartChangeEvents.clear();
    panel.zoomInRange(1.0, 2.0);
    assertEquals(1, this.chartChangeEvents.size());
}
 
Example #20
Source File: ChartPanelTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that a call to the zoomInDomain() method, for a plot with more
 * than one domain axis, generates just one ChartChangeEvent.
 */
@Test
public void test2502355_zoomInDomain() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X",
            "Y", dataset, PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainAxis(1, new NumberAxis("X2"));
    ChartPanel panel = new ChartPanel(chart);
    chart.addChangeListener(this);
    this.chartChangeEvents.clear();
    panel.zoomInDomain(1.0, 2.0);
    assertEquals(1, this.chartChangeEvents.size());
}
 
Example #21
Source File: DefaultXYDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the indexOf(Comparable) method.
 */
public void testIndexOf() {
    DefaultXYDataset d = createSampleDataset1();
    assertEquals(0, d.indexOf("S1"));
    assertEquals(1, d.indexOf("S2"));
    assertEquals(-1, d.indexOf("Green Eggs and Ham"));
    assertEquals(-1, d.indexOf(null));
}
 
Example #22
Source File: ChartPanelTest.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks that a call to the restoreAutoBounds() method generates just one
 * ChartChangeEvent.
 */
@Test
public void test2502355_restoreAutoBounds() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X",
            "Y", dataset, PlotOrientation.VERTICAL, false, false, false);
    ChartPanel panel = new ChartPanel(chart);
    chart.addChangeListener(this);
    this.chartChangeEvents.clear();
    panel.restoreAutoBounds();
    assertEquals(1, this.chartChangeEvents.size());
}
 
Example #23
Source File: ChartPanelTest.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks that a call to the zoomInBoth() method generates just one
 * ChartChangeEvent.
 */
@Test
public void test2502355_zoomInBoth() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X",
            "Y", dataset, PlotOrientation.VERTICAL, false, false, false);
    ChartPanel panel = new ChartPanel(chart);
    chart.addChangeListener(this);
    this.chartChangeEvents.clear();
    panel.zoomInBoth(1.0, 2.0);
    assertEquals(1, this.chartChangeEvents.size());
}
 
Example #24
Source File: ChartPanelTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that a call to the zoom() method generates just one
 * ChartChangeEvent.
 */
@Test
public void test2502355_zoom() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X",
            "Y", dataset, PlotOrientation.VERTICAL, false, false, false);
    ChartPanel panel = new ChartPanel(chart);
    chart.addChangeListener(this);
    this.chartChangeEvents.clear();
    panel.zoom(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertEquals(1, this.chartChangeEvents.size());
}
 
Example #25
Source File: DatasetUtilitiesTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check that NaN values in the dataset are ignored.
 */
@Test
public void testIterateDomainBounds_NaN() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    double[] x = new double[] {1.0, 2.0, Double.NaN, 3.0};
    double[] y = new double[] {9.0, 8.0, 7.0, 6.0};
    dataset.addSeries("S1", new double[][] {x, y});
    Range r = DatasetUtilities.iterateDomainBounds(dataset);
    assertEquals(1.0, r.getLowerBound(), EPSILON);
    assertEquals(3.0, r.getUpperBound(), EPSILON);
}
 
Example #26
Source File: TimeSeriesURLGeneratorTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A basic check for the generateURL() method.
 */
@Test
public void testGenerateURL() {
    TimeSeriesURLGenerator g = new TimeSeriesURLGenerator();
    DefaultXYDataset dataset = new DefaultXYDataset();
    dataset.addSeries("Series '1'", new double[][] {{1.0, 2.0},
            {3.0, 4.0}});
    String s = g.generateURL(dataset, 0, 0);
    assertTrue(s.startsWith("index.html?series=Series+%271%27&item="));
}
 
Example #27
Source File: ChartPanelTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * In version 1.0.13 there is a bug where enabling the mouse wheel handler
 * twice would in fact disable it.
 */
@Test
public void testSetMouseWheelEnabled() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X",
            "Y", dataset, PlotOrientation.VERTICAL, false, false, false);
    ChartPanel panel = new ChartPanel(chart);
    panel.setMouseWheelEnabled(true);
    assertTrue(panel.isMouseWheelEnabled());
    panel.setMouseWheelEnabled(true);
    assertTrue(panel.isMouseWheelEnabled());
    panel.setMouseWheelEnabled(false);
    assertFalse(panel.isMouseWheelEnabled());
}
 
Example #28
Source File: ChartPanelTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks that a call to the zoomInRange() method, for a plot with more
 * than one range axis, generates just one ChartChangeEvent.
 */
@Test
public void test2502355_zoomInRange() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X",
            "Y", dataset, PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeAxis(1, new NumberAxis("X2"));
    ChartPanel panel = new ChartPanel(chart);
    chart.addChangeListener(this);
    this.chartChangeEvents.clear();
    panel.zoomInRange(1.0, 2.0);
    assertEquals(1, this.chartChangeEvents.size());
}
 
Example #29
Source File: ChartPanelTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks that a call to the restoreAutoRangeBounds() method, for a plot
 * with more than one range axis, generates just one ChartChangeEvent.
 */
public void test2502355_restoreAutoRangeBounds() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X",
            "Y", dataset, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeAxis(1, new NumberAxis("X2"));
    ChartPanel panel = new ChartPanel(chart);
    chart.addChangeListener(this);
    this.chartChangeEvents.clear();
    panel.restoreAutoRangeBounds();
    assertEquals(1, this.chartChangeEvents.size());
}
 
Example #30
Source File: XYImagePlot.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public void setImageDataBounds(Rectangle2D imageDataBounds) {
    synchronized (imageLock) {
        this.imageDataBounds = (Rectangle2D) imageDataBounds.clone();
        DefaultXYDataset xyDataset = new DefaultXYDataset();
        xyDataset.addSeries("Image Data Bounds", new double[][]{
                {imageDataBounds.getMinX(), imageDataBounds.getMaxX()},
                {imageDataBounds.getMinY(), imageDataBounds.getMaxY()}
        });
        setDataset(xyDataset);
        getDomainAxis().setRange(imageDataBounds.getMinX(), imageDataBounds.getMaxX());
        getRangeAxis().setRange(imageDataBounds.getMinY(), imageDataBounds.getMaxY());
    }
}