/** * A check for the NullPointerException in bug 2275695. */ public void test2275695() { JFreeChart chart = ChartFactory.createStackedBarChart("Test", "Category", "Value", null, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainAxis(new SubCategoryAxis("SubCategoryAxis")); 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); }
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { SubCategoryAxis a1 = new SubCategoryAxis("Test"); SubCategoryAxis a2 = new SubCategoryAxis("Test"); assertTrue(a1.equals(a2)); assertTrue(a2.equals(a1)); // subcategories a1.addSubCategory("Sub 1"); assertFalse(a1.equals(a2)); a2.addSubCategory("Sub 1"); assertTrue(a1.equals(a2)); // subLabelFont a1.setSubLabelFont(new Font("Serif", Font.BOLD, 15)); assertFalse(a1.equals(a2)); a2.setSubLabelFont(new Font("Serif", Font.BOLD, 15)); assertTrue(a1.equals(a2)); // subLabelPaint a1.setSubLabelPaint(Color.red); assertFalse(a1.equals(a2)); a2.setSubLabelPaint(Color.red); assertTrue(a1.equals(a2)); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashCode() { SubCategoryAxis a1 = new SubCategoryAxis("Test"); SubCategoryAxis a2 = new SubCategoryAxis("Test"); assertTrue(a1.equals(a2)); int h1 = a1.hashCode(); int h2 = a2.hashCode(); assertEquals(h1, h2); }
/** * Applies the attributes for this theme to a {@link CategoryAxis}. * * @param axis the axis (<code>null</code> not permitted). */ protected void applyToCategoryAxis(CategoryAxis axis) { axis.setLabelFont(this.largeFont); axis.setLabelPaint(this.axisLabelPaint); axis.setTickLabelFont(this.regularFont); axis.setTickLabelPaint(this.tickLabelPaint); if (axis instanceof SubCategoryAxis) { SubCategoryAxis sca = (SubCategoryAxis) axis; sca.setSubLabelFont(this.regularFont); sca.setSubLabelPaint(this.tickLabelPaint); } }
/** * Applies the attributes for this theme to a {@link CategoryAxis}. * * @param axis the axis ({@code null} not permitted). */ protected void applyToCategoryAxis(CategoryAxis axis) { axis.setLabelFont(this.largeFont); axis.setLabelPaint(this.axisLabelPaint); axis.setTickLabelFont(this.regularFont); axis.setTickLabelPaint(this.tickLabelPaint); if (axis instanceof SubCategoryAxis) { SubCategoryAxis sca = (SubCategoryAxis) axis; sca.setSubLabelFont(this.regularFont); sca.setSubLabelPaint(this.tickLabelPaint); } }
protected JFreeChart createLegend(CategoryDataset dataset) { // JFreeChart chart = ChartFactory.createAreaChart( JFreeChart chart = ChartFactory.createStackedBarChart( chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); KeyToGroupMap map = new KeyToGroupMap("G1"); map.mapKeyToGroup("Product 1 (US)", "G1"); map.mapKeyToGroup("Product 1 (Europe)", "G1"); map.mapKeyToGroup("Product 1 (Asia)", "G1"); map.mapKeyToGroup("Product 1 (Middle East)", "G1"); map.mapKeyToGroup("Product 2 (US)", "G2"); map.mapKeyToGroup("Product 2 (Europe)", "G2"); map.mapKeyToGroup("Product 2 (Asia)", "G2"); map.mapKeyToGroup("Product 2 (Middle East)", "G2"); map.mapKeyToGroup("Product 3 (US)", "G3"); map.mapKeyToGroup("Product 3 (Europe)", "G3"); map.mapKeyToGroup("Product 3 (Asia)", "G3"); map.mapKeyToGroup("Product 3 (Middle East)", "G3"); renderer.setSeriesToGroupMap(map); renderer.setItemMargin(0.10); renderer.setDrawBarOutline(false); Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f, new Color(0x88, 0x88, 0xFF)); renderer.setSeriesPaint(0, p1); renderer.setSeriesPaint(4, p1); renderer.setSeriesPaint(8, p1); Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f, new Color(0x88, 0xFF, 0x88)); renderer.setSeriesPaint(1, p2); renderer.setSeriesPaint(5, p2); renderer.setSeriesPaint(9, p2); Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f, new Color(0xFF, 0x88, 0x88)); renderer.setSeriesPaint(2, p3); renderer.setSeriesPaint(6, p3); renderer.setSeriesPaint(10, p3); Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f, new Color(0xFF, 0xFF, 0x88)); renderer.setSeriesPaint(3, p4); renderer.setSeriesPaint(7, p4); renderer.setSeriesPaint(11, p4); renderer.setGradientPaintTransformer( new StandardGradientPaintTransformer( GradientPaintTransformType.HORIZONTAL)); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); SubCategoryAxis domainAxis = new SubCategoryAxis("Product / Month"); domainAxis.setCategoryMargin(0.05); domainAxis.addSubCategory("Product 1"); domainAxis.addSubCategory("Product 2"); domainAxis.addSubCategory("Product 3"); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainAxis(domainAxis); //plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT); plot.setRenderer(renderer); return chart; }
public void resetDomainAxis(final IScope scope) { // TODO Auto-generated method stub final CategoryPlot pp = (CategoryPlot) chart.getPlot(); if (this.useSubAxis) { final SubCategoryAxis newAxis = new SubCategoryAxis(pp.getDomainAxis().getLabel()); pp.setDomainAxis(newAxis); } pp.getDomainAxis().setAxisLinePaint(axesColor); pp.getDomainAxis().setTickLabelFont(getTickFont()); pp.getDomainAxis().setLabelFont(getLabelFont()); if (textColor != null) { pp.getDomainAxis().setLabelPaint(textColor); pp.getDomainAxis().setTickLabelPaint(textColor); } if (gap > 0) { pp.getDomainAxis().setCategoryMargin(gap); pp.getDomainAxis().setUpperMargin(gap); pp.getDomainAxis().setLowerMargin(gap); } if (this.useSubAxis && !this.useMainAxisLabel) { pp.getDomainAxis().setTickLabelsVisible(false); // pp.getDomainAxis().setTickLabelPaint(this.backgroundColor); // pp.getDomainAxis().setLabelFont(new Font(labelFontFace, // labelFontStyle, 1)); } if (!this.getYTickLineVisible(scope)) { pp.setDomainGridlinesVisible(false); } if (!this.getYTickLineVisible(scope)) { pp.setRangeCrosshairVisible(false); } if (!this.getYTickValueVisible(scope)) { pp.getRangeAxis().setTickMarksVisible(false); pp.getRangeAxis().setTickLabelsVisible(false); } if (!this.getXTickValueVisible(scope)) { pp.getDomainAxis().setTickMarksVisible(false); pp.getDomainAxis().setTickLabelsVisible(false); } }