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.");
}
}
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()));
}
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.");
}
}
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;
}
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.");
}
}
Aggregations