/** * Test chart drawing with an empty dataset to ensure that this special * case doesn't cause any exceptions. */ public void testDrawWithEmptyDataset() { boolean success = false; JFreeChart chart = ChartFactory.createStackedXYAreaChart("title", "x", "y", new DefaultTableXYDataset(), PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(new StackedXYAreaRenderer2()); 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) { success = false; } assertTrue(success); }
/** * Check that the renderer is calculating the range bounds correctly. */ public void testFindRangeBounds() { TableXYDataset dataset = RendererXYPackageTests.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())); }
/** * Creates a sample chart. * * @param dataset the dataset for the chart. * * @return a sample chart. */ protected JFreeChart createChart(TableXYDataset dataset) { JFreeChart chart = ChartFactory.createStackedXYAreaChart( chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation !legendPanelOn, // legend true, // tooltips false // urls ); XYPlot plot = (XYPlot) chart.getPlot(); StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(0, renderer); renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); setXSummary(dataset); return chart; }
/** * Creates a chart. * * @param dataset the dataset. * * @return a chart. */ protected JFreeChart createChart(TableXYDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createStackedXYAreaChart( chartTitle, // chart title domainLabel, // x axis label rangeLabel, // y axis label dataset, // data PlotOrientation.VERTICAL, !legendPanelOn, // include legend true, // tooltips false // urls ); XYPlot plot = (XYPlot) chart.getPlot(); StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(0, renderer); return chart; }
protected JFreeChart createLegend(TableXYDataset dataset) { // JFreeChart chart = ChartFactory.createAreaChart( JFreeChart chart = ChartFactory.createStackedXYAreaChart( chartTitle, // chart title domainLabel, // x axis label rangeLabel, // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... XYPlot plot = (XYPlot) chart.getPlot(); StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(0, renderer); renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); return chart; }
private JFreeChart createTableXYAreaChart(String title, String xLabel, String yLabel, TableXYDataset dataset) { JFreeChart chart = ChartFactory.createStackedXYAreaChart( title, // chart title xLabel, // x axis label yLabel, // y axis label dataset, // data orientation, true, // include legend true, // tooltips false // urls ); XYPlot plot = (XYPlot) chart.getPlot(); StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(); // renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(0, renderer); return chart; }
/** * Test chart drawing with an empty dataset to ensure that this special * case doesn't cause any exceptions. */ public void testDrawWithEmptyDataset() { boolean success = false; JFreeChart chart = ChartFactory.createStackedXYAreaChart("title", "x", "y", new DefaultTableXYDataset(), true); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(new StackedXYAreaRenderer2()); 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) { success = false; } assertTrue(success); }
/** * Check that the renderer is calculating the range bounds correctly. */ public void testFindRangeBounds() { TableXYDataset dataset = RendererXYPackageTests.createTestTableXYDataset(); JFreeChart chart = ChartFactory.createStackedXYAreaChart( "Test Chart", "X", "Y", dataset, 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())); }
/** * Creates a stacked XY area plot. The chart object returned by this * method uses an {@link XYPlot} instance as the plot, with a * {@link NumberAxis} for the domain axis, a {@link NumberAxis} as the * range axis, and a {@link StackedXYAreaRenderer2} as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * * @return A stacked XY area chart. */ public static JFreeChart createStackedXYAreaChart(String title, String xAxisLabel, String yAxisLabel, TableXYDataset dataset, boolean legend) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); NumberAxis yAxis = new NumberAxis(yAxisLabel); StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setOutline(true); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setRangeAxis(yAxis); // forces recalculation of the axis range JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Test that the equals() method distinguishes all fields. */ public void testEquals() { StackedXYAreaRenderer2 r1 = new StackedXYAreaRenderer2(); StackedXYAreaRenderer2 r2 = new StackedXYAreaRenderer2(); assertEquals(r1, r2); assertEquals(r2, r1); r1.setRoundXCoordinates(!r1.getRoundXCoordinates()); assertFalse(r1.equals(r2)); r2.setRoundXCoordinates(r1.getRoundXCoordinates()); assertTrue(r1.equals(r2)); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { StackedXYAreaRenderer2 r1 = new StackedXYAreaRenderer2(); StackedXYAreaRenderer2 r2 = new StackedXYAreaRenderer2(); assertTrue(r1.equals(r2)); int h1 = r1.hashCode(); int h2 = r2.hashCode(); assertEquals(h1, h2); }
public void fitnessGraph() { final FitnessDistributionDataset dataset = new FitnessDistributionDataset(this.eventBus); final JFreeChart chart = ChartFactory.createStackedXYAreaChart("Fitness distribution", "iteration", "distribution", dataset, PlotOrientation.VERTICAL, true, true, false); final StackedXYAreaRenderer2 stackedxyarearenderer2 = new StackedXYAreaRenderer2(); ((XYPlot) chart.getPlot()).setRenderer(0, stackedxyarearenderer2); final ChartPanel panel = new ChartPanel(chart); final JFrame jFrame = new JFrame(); jFrame.setContentPane(panel); jFrame.pack(); jFrame.setVisible(true); }
/** * Verify that this class implements {@link PublicCloneable}. */ public void testPublicCloneable() { StackedXYAreaRenderer2 r1 = new StackedXYAreaRenderer2(); assertTrue(r1 instanceof PublicCloneable); }