/** * 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"); 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()); }
private JFreeChart createCategoryStepChart(String title, String xLabel, String yLabel, CategoryDataset dataset) { CategoryItemRenderer renderer = new CategoryStepRenderer(true); CategoryAxis domainAxis = new CategoryAxis(xLabel); NumberAxis rangeAxis = new NumberAxis(yLabel); CategoryPlot plot = new CategoryPlot( dataset, domainAxis, rangeAxis, renderer ); JFreeChart chart = new JFreeChart(title, plot); return chart; }
/** * Creates a chart. * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { CategoryItemRenderer renderer = new CategoryStepRenderer(true); CategoryAxis domainAxis = new CategoryAxis(domainLabel); NumberAxis rangeAxis = new NumberAxis(rangeLabel); CategoryPlot plot = new CategoryPlot( dataset, domainAxis, rangeAxis, renderer ); JFreeChart chart = new JFreeChart(chartTitle, plot); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); AbstractCategoryItemRenderer renderer2 = (AbstractCategoryItemRenderer)plot.getRenderer(); renderer2.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.addCategoryLabelToolTip("Type 1", "The first type."); domainAxis.addCategoryLabelToolTip("Type 2", "The second type."); domainAxis.addCategoryLabelToolTip("Type 3", "The third type."); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelAngle(0 * Math.PI / 2.0); // OPTIONAL CUSTOMISATION COMPLETED. setCategorySummary(dataset); if (legendPanelOn) chart.removeLegend(); return chart; }
/** * Check that this class implements PublicCloneable. */ public void testPublicCloneable() { CategoryStepRenderer r1 = new CategoryStepRenderer(false); assertTrue(r1 instanceof PublicCloneable); }