public static void setLineRender(CategoryPlot plot, boolean isShowDataLabels, boolean isShapesVisible) { plot.setNoDataMessage(NO_DATA_MSG); plot.setInsets(new RectangleInsets(10, 10, 0, 10), false); LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setStroke(new BasicStroke(1.5F)); if (isShowDataLabels) { renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, NumberFormat.getInstance())); renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.BOTTOM_CENTER)); } renderer.setBaseShapesVisible(isShapesVisible); setXAixs(plot); setYAixs(plot); }
/** * Returns <code>true</code> if the specified anchor point is inside a bar. * * @param anchor the anchor point. * * @return A boolean. */ private boolean isInternalAnchor(ItemLabelAnchor anchor) { return anchor == ItemLabelAnchor.CENTER || anchor == ItemLabelAnchor.INSIDE1 || anchor == ItemLabelAnchor.INSIDE2 || anchor == ItemLabelAnchor.INSIDE3 || anchor == ItemLabelAnchor.INSIDE4 || anchor == ItemLabelAnchor.INSIDE5 || anchor == ItemLabelAnchor.INSIDE6 || anchor == ItemLabelAnchor.INSIDE7 || anchor == ItemLabelAnchor.INSIDE8 || anchor == ItemLabelAnchor.INSIDE9 || anchor == ItemLabelAnchor.INSIDE10 || anchor == ItemLabelAnchor.INSIDE11 || anchor == ItemLabelAnchor.INSIDE12; }
/** * Constructs a new renderer with the specified '3D effect'. * * @param xOffset the x-offset for the 3D effect. * @param yOffset the y-offset for the 3D effect. */ public BarRenderer3D(double xOffset, double yOffset) { super(); this.xOffset = xOffset; this.yOffset = yOffset; this.wallPaint = DEFAULT_WALL_PAINT; // set the default item label positions ItemLabelPosition p1 = new ItemLabelPosition( ItemLabelAnchor.INSIDE12, TextAnchor.TOP_CENTER ); setPositiveItemLabelPosition(p1); ItemLabelPosition p2 = new ItemLabelPosition( ItemLabelAnchor.INSIDE12, TextAnchor.TOP_CENTER ); setNegativeItemLabelPosition(p2); }
/** * Constructs a new renderer with the specified '3D effect'. * * @param xOffset the x-offset for the 3D effect. * @param yOffset the y-offset for the 3D effect. */ public BarRenderer3D(double xOffset, double yOffset) { super(); this.xOffset = xOffset; this.yOffset = yOffset; this.wallPaint = DEFAULT_WALL_PAINT; // set the default item label positions ItemLabelPosition p1 = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.TOP_CENTER); setPositiveItemLabelPosition(p1); ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.TOP_CENTER); setNegativeItemLabelPosition(p2); }
/** * Constructs a new renderer with the specified '3D effect'. * * @param xOffset the x-offset for the 3D effect. * @param yOffset the y-offset for the 3D effect. */ public BarRenderer3D(double xOffset, double yOffset) { super(); this.xOffset = xOffset; this.yOffset = yOffset; this.wallPaint = DEFAULT_WALL_PAINT; // set the default item label positions ItemLabelPosition p1 = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.TOP_CENTER); setBasePositiveItemLabelPosition(p1); ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.TOP_CENTER); setBaseNegativeItemLabelPosition(p2); }
/** * Returns {@code true} if the specified anchor point is inside a bar. * * @param anchor the anchor point. * * @return A boolean. */ private boolean isInternalAnchor(ItemLabelAnchor anchor) { return anchor == ItemLabelAnchor.CENTER || anchor == ItemLabelAnchor.INSIDE1 || anchor == ItemLabelAnchor.INSIDE2 || anchor == ItemLabelAnchor.INSIDE3 || anchor == ItemLabelAnchor.INSIDE4 || anchor == ItemLabelAnchor.INSIDE5 || anchor == ItemLabelAnchor.INSIDE6 || anchor == ItemLabelAnchor.INSIDE7 || anchor == ItemLabelAnchor.INSIDE8 || anchor == ItemLabelAnchor.INSIDE9 || anchor == ItemLabelAnchor.INSIDE10 || anchor == ItemLabelAnchor.INSIDE11 || anchor == ItemLabelAnchor.INSIDE12; }
/** * Creates a bar chart. The chart object returned by this method uses a * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis} * for the domain axis, a {@link NumberAxis} as the range axis, and a * {@link BarRenderer} as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value 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 bar chart. */ public static JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, boolean legend) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); BarRenderer renderer = new BarRenderer(); ItemLabelPosition position1 = new ItemLabelPosition( ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); renderer.setBasePositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition( ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setBaseNegativeItemLabelPosition(position2); renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** Customize renderer. */ private void customizeRenderer(CategoryPlot plot) { BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setMaximumBarWidth(0.5); renderer.setSeriesPaint(0, Color.BLACK); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelPaint(Color.white); renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition( ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0)); renderer.setBarPainter(new StandardBarPainter()); renderer.setShadowVisible(false); }