Search in sources :

Example 6 with DefaultTableXYDataset

use of org.jfree.data.xy.DefaultTableXYDataset in project SIMVA-SoS by SESoS.

the class XYStepRendererTest method testDrawWithNullValue.

/**
 * Draws the chart with a <code>null</code> value in the dataset to make
 * sure that no exceptions are thrown.
 */
@Test
public void testDrawWithNullValue() {
    try {
        DefaultTableXYDataset dataset = new DefaultTableXYDataset();
        XYSeries s1 = new XYSeries("Series 1", true, false);
        s1.add(5.0, 5.0);
        s1.add(10.0, null);
        s1.add(15.0, 9.5);
        s1.add(20.0, 7.5);
        dataset.addSeries(s1);
        XYSeries s2 = new XYSeries("Series 2", true, false);
        s2.add(5.0, 5.0);
        s2.add(10.0, 15.5);
        s2.add(15.0, null);
        s2.add(20.0, null);
        dataset.addSeries(s2);
        XYPlot plot = new XYPlot(dataset, new NumberAxis("X"), new NumberAxis("Y"), new XYStepRenderer());
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */
        chart.createBufferedImage(300, 200, null);
    } catch (NullPointerException e) {
        fail("No exception should be thrown.");
    }
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) DefaultTableXYDataset(org.jfree.data.xy.DefaultTableXYDataset) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.Test)

Example 7 with DefaultTableXYDataset

use of org.jfree.data.xy.DefaultTableXYDataset in project SIMVA-SoS by SESoS.

the class StackedXYAreaRenderer2Test method testFindRangeBounds.

/**
 * Check that the renderer is calculating the range bounds correctly.
 */
@Test
public void testFindRangeBounds() {
    TableXYDataset dataset = RendererXYPackageUtils.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart("Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2();
    plot.setRenderer(renderer);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    Range bounds = rangeAxis.getRange();
    assertTrue(bounds.contains(6.0));
    assertTrue(bounds.contains(8.0));
    // try null argument
    assertNull(renderer.findRangeBounds(null));
    // try empty dataset
    assertNull(renderer.findRangeBounds(new DefaultTableXYDataset()));
}
Also used : DefaultTableXYDataset(org.jfree.data.xy.DefaultTableXYDataset) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) TableXYDataset(org.jfree.data.xy.TableXYDataset) DefaultTableXYDataset(org.jfree.data.xy.DefaultTableXYDataset) Range(org.jfree.data.Range) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.Test)

Example 8 with DefaultTableXYDataset

use of org.jfree.data.xy.DefaultTableXYDataset in project SIMVA-SoS by SESoS.

the class XYTitleAnnotationTest method testDrawWithNullInfo.

/**
 * Draws the chart with a <code>null</code> info object to make sure that
 * no exceptions are thrown.
 */
@Test
public void testDrawWithNullInfo() {
    try {
        DefaultTableXYDataset dataset = new DefaultTableXYDataset();
        XYSeries s1 = new XYSeries("Series 1", true, false);
        s1.add(5.0, 5.0);
        s1.add(10.0, 15.5);
        s1.add(15.0, 9.5);
        s1.add(20.0, 7.5);
        dataset.addSeries(s1);
        XYSeries s2 = new XYSeries("Series 2", true, false);
        s2.add(5.0, 5.0);
        s2.add(10.0, 15.5);
        s2.add(15.0, 9.5);
        s2.add(20.0, 3.5);
        dataset.addSeries(s2);
        XYPlot plot = new XYPlot(dataset, new NumberAxis("X"), new NumberAxis("Y"), new XYLineAndShapeRenderer());
        plot.addAnnotation(new XYTitleAnnotation(5.0, 6.0, new TextTitle("Hello World!")));
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */
        chart.createBufferedImage(300, 200, null);
    } catch (NullPointerException e) {
        fail("There should be no exception.");
    }
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) DefaultTableXYDataset(org.jfree.data.xy.DefaultTableXYDataset) TextTitle(org.jfree.chart.title.TextTitle) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.Test)

Example 9 with DefaultTableXYDataset

use of org.jfree.data.xy.DefaultTableXYDataset in project xwiki-platform by xwiki.

the class TableXYDatasetFactory method create.

public XYDataset create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException {
    // String type = params.getStringParam("type");
    String dataSeries = params.getString(ChartParams.SERIES);
    DefaultTableXYDataset dataset = new DefaultTableXYDataset();
    if (dataSeries.equals("columns")) {
        if (!dataSource.hasHeaderColumn()) {
            throw new GenerateException("Header column required");
        }
        for (int column = 0; column < dataSource.getColumnCount(); column++) {
            XYSeries series = new XYSeries(dataSource.hasHeaderRow() ? dataSource.getHeaderRowValue(column) : ("Series " + (column + 1)), false, false);
            for (int row = 0; row < dataSource.getRowCount(); row++) {
                series.add(Double.parseDouble(dataSource.getHeaderColumnValue(row)), dataSource.getCell(row, column));
            }
            dataset.addSeries(series);
        }
    } else if (dataSeries.equals("rows")) {
        if (!dataSource.hasHeaderRow()) {
            throw new GenerateException("Header row required");
        }
        for (int row = 0; row < dataSource.getRowCount(); row++) {
            XYSeries series = new XYSeries(dataSource.hasHeaderColumn() ? dataSource.getHeaderColumnValue(row) : ("Series " + (row + 1)), false, false);
            for (int column = 0; column < dataSource.getColumnCount(); column++) {
                series.add(Double.parseDouble(dataSource.getHeaderRowValue(column)), dataSource.getCell(row, column));
            }
            dataset.addSeries(series);
        }
    } else {
        throw new GenerateException("Invalid series parameter:" + dataSeries);
    }
    return dataset;
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) DefaultTableXYDataset(org.jfree.data.xy.DefaultTableXYDataset) GenerateException(com.xpn.xwiki.plugin.charts.exceptions.GenerateException)

Example 10 with DefaultTableXYDataset

use of org.jfree.data.xy.DefaultTableXYDataset in project SIMVA-SoS by SESoS.

the class XYBoxAnnotationTest method testDrawWithNullInfo.

/**
 * Draws the chart with a <code>null</code> info object to make sure that
 * no exceptions are thrown.
 */
public void testDrawWithNullInfo() {
    try {
        DefaultTableXYDataset dataset = new DefaultTableXYDataset();
        XYSeries s1 = new XYSeries("Series 1", true, false);
        s1.add(5.0, 5.0);
        s1.add(10.0, 15.5);
        s1.add(15.0, 9.5);
        s1.add(20.0, 7.5);
        dataset.addSeries(s1);
        XYSeries s2 = new XYSeries("Series 2", true, false);
        s2.add(5.0, 5.0);
        s2.add(10.0, 15.5);
        s2.add(15.0, 9.5);
        s2.add(20.0, 3.5);
        dataset.addSeries(s2);
        XYPlot plot = new XYPlot(dataset, new NumberAxis("X"), new NumberAxis("Y"), new XYLineAndShapeRenderer());
        plot.addAnnotation(new XYBoxAnnotation(10.0, 12.0, 3.0, 4.0, new BasicStroke(1.2f), Color.red, Color.blue));
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */
        chart.createBufferedImage(300, 200, null);
    } catch (NullPointerException e) {
        fail("No exception should be triggered.");
    }
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) BasicStroke(java.awt.BasicStroke) DefaultTableXYDataset(org.jfree.data.xy.DefaultTableXYDataset) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

DefaultTableXYDataset (org.jfree.data.xy.DefaultTableXYDataset)15 XYSeries (org.jfree.data.xy.XYSeries)12 JFreeChart (org.jfree.chart.JFreeChart)11 XYPlot (org.jfree.chart.plot.XYPlot)11 Test (org.junit.Test)11 NumberAxis (org.jfree.chart.axis.NumberAxis)10 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)2 Range (org.jfree.data.Range)2 GenerateException (com.xpn.xwiki.plugin.charts.exceptions.GenerateException)1 BasicStroke (java.awt.BasicStroke)1 Graphics2D (java.awt.Graphics2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1 TextTitle (org.jfree.chart.title.TextTitle)1 TableXYDataset (org.jfree.data.xy.TableXYDataset)1