List of usage examples for org.jfree.chart.renderer.category WaterfallBarRenderer WaterfallBarRenderer
public WaterfallBarRenderer()
From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.WaterfallBarRendererCustomizer.java
@Override public void customize(JFreeChart chart, ReportParameters reportParameters) { BarRenderer categoryRenderer = (BarRenderer) chart.getCategoryPlot().getRenderer(); WaterfallBarRenderer renderer = new WaterfallBarRenderer(); renderer.setBaseItemLabelsVisible(categoryRenderer.getBaseItemLabelsVisible()); renderer.setBaseItemLabelFont(categoryRenderer.getBaseItemLabelFont()); renderer.setBaseItemLabelPaint(categoryRenderer.getBaseItemLabelPaint()); renderer.setBaseItemLabelGenerator(categoryRenderer.getBaseItemLabelGenerator()); renderer.setShadowVisible(categoryRenderer.getShadowsVisible()); CategoryDataset categoryDataset = chart.getCategoryPlot().getDataset(); if (categoryDataset != null) { for (int i = 0; i < categoryDataset.getRowCount(); i++) { Paint seriesOutlinePaint = categoryRenderer.getSeriesOutlinePaint(i); if (seriesOutlinePaint != null) { renderer.setSeriesOutlinePaint(i, seriesOutlinePaint); }/*from ww w .j av a 2 s. co m*/ Paint seriesPaint = categoryRenderer.getSeriesPaint(i); if (seriesPaint != null) { renderer.setSeriesPaint(i, seriesPaint); } } } renderer.setItemMargin(categoryRenderer.getItemMargin()); GradientPaintTransformer gradientPaintTransformer = categoryRenderer.getGradientPaintTransformer(); if (gradientPaintTransformer != null) { renderer.setGradientPaintTransformer(gradientPaintTransformer); } if (firstBarPaint != null) { renderer.setFirstBarPaint(firstBarPaint); } if (lastBarPaint != null) { renderer.setLastBarPaint(lastBarPaint); } if (positiveBarPaint != null) { renderer.setPositiveBarPaint(positiveBarPaint); } if (negativeBarPaint != null) { renderer.setNegativeBarPaint(negativeBarPaint); } chart.getCategoryPlot().setRenderer(renderer); }
From source file:org.jfree.chart.demo.WaterfallChartDemo2.java
/** * Returns the chart.// w w w .j a va 2 s .c o m * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final CategoryAxis xAxis = new CategoryAxis("Category"); final NumberAxis yAxis = new NumberAxis("$ in Thousands"); yAxis.setLowerMargin(0.10); yAxis.setUpperMargin(0.10); // create a custom tick unit collection... final DecimalFormat formatter = new DecimalFormat("##,###"); formatter.setNegativePrefix("("); formatter.setNegativeSuffix(")"); final TickUnits standardUnits = new TickUnits(); standardUnits.add(new NumberTickUnit(200, formatter)); standardUnits.add(new NumberTickUnit(500, formatter)); standardUnits.add(new NumberTickUnit(1000, formatter)); standardUnits.add(new NumberTickUnit(2000, formatter)); standardUnits.add(new NumberTickUnit(5000, formatter)); yAxis.setStandardTickUnits(standardUnits); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** final DecimalFormat labelFormatter = new DecimalFormat("##,###"); labelFormatter.setNegativePrefix("("); labelFormatter.setNegativeSuffix(")"); final WaterfallBarRenderer renderer = new WaterfallBarRenderer(); // renderer.setLabelGenerator( // new StandardCategoryLabelGenerator("{2}", labelFormatter) // ); renderer.setItemLabelsVisible(Boolean.TRUE); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); final ValueMarker baseline = new ValueMarker(0.0); baseline.setPaint(Color.blue); baseline.setStroke(new BasicStroke(1.1f)); plot.addRangeMarker(baseline, Layer.FOREGROUND); final JFreeChart chart = new JFreeChart("OM WaterFall Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(Color.white); return chart; }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java
private static JFreeChart createWaterfallChart(CategoryDataset dataset) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); categoryAxis.setCategoryMargin(0.0); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); WaterfallBarRenderer renderer = new WaterfallBarRenderer(); if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, Math.PI / 2.0); renderer.setBasePositiveItemLabelPosition(position); renderer.setBaseNegativeItemLabelPosition(position); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0); renderer.setBasePositiveItemLabelPosition(position); renderer.setBaseNegativeItemLabelPosition(position); }/*from ww w. j a v a 2 s. c o m*/ if (tooltips) { StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator(); renderer.setBaseToolTipGenerator(generator); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.clearRangeMarkers(); Marker baseline = new ValueMarker(0.0); baseline.setPaint(Color.black); plot.addRangeMarker(baseline, Layer.FOREGROUND); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart("Waterfall Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); // GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); // AbstractRenderer#setSeriesPaint(int, Paint) are ignored; // renderer.setSeriesPaint(0, gp0); // renderer.setSeriesPaint(1, gp1); // renderer.setSeriesPaint(2, gp2); //?? renderer.setFirstBarPaint(gp0); renderer.setLastBarPaint(gp2); renderer.setPositiveBarPaint(Color.orange); renderer.setNegativeBarPaint(Color.cyan); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); return chart; }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a waterfall 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 WaterfallBarRenderer} as the renderer. * //from w w w . j ava 2 s .com * @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 orientation the plot orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A waterfall chart. */ public static JFreeChart createWaterfallChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); categoryAxis.setCategoryMargin(0.0); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); WaterfallBarRenderer renderer = new WaterfallBarRenderer(); if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, Math.PI / 2.0); renderer.setBasePositiveItemLabelPosition(position); renderer.setBaseNegativeItemLabelPosition(position); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0); renderer.setBasePositiveItemLabelPosition(position); renderer.setBaseNegativeItemLabelPosition(position); } if (tooltips) { StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator(); renderer.setBaseToolTipGenerator(generator); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.clearRangeMarkers(); Marker baseline = new ValueMarker(0.0); baseline.setPaint(Color.black); plot.addRangeMarker(baseline, Layer.FOREGROUND); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:KIDLYFactory.java
/** * Creates a waterfall 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 WaterfallBarRenderer} 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).//from w w w.j av a 2 s. c o m * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A waterfall chart. */ public static JFreeChart createWaterfallChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); categoryAxis.setCategoryMargin(0.0); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); WaterfallBarRenderer renderer = new WaterfallBarRenderer(); if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, Math.PI / 2.0); renderer.setBasePositiveItemLabelPosition(position); renderer.setBaseNegativeItemLabelPosition(position); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0); renderer.setBasePositiveItemLabelPosition(position); renderer.setBaseNegativeItemLabelPosition(position); } if (tooltips) { StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator(); renderer.setBaseToolTipGenerator(generator); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.clearRangeMarkers(); Marker baseline = new ValueMarker(0.0); baseline.setPaint(Color.black); plot.addRangeMarker(baseline, Layer.FOREGROUND); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
From source file:org.jfree.chart.ChartFactory.java
/** * Creates a waterfall 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 WaterfallBarRenderer} as the renderer. * * @param title the chart title ({@code null} permitted). * @param categoryAxisLabel the label for the category axis * ({@code null} permitted). * @param valueAxisLabel the label for the value axis ({@code null} * permitted).// w w w . j a va2s.c o m * @param dataset the dataset for the chart ({@code null} permitted). * * @return A waterfall chart. */ public static JFreeChart createWaterfallChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); categoryAxis.setCategoryMargin(0.0); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); WaterfallBarRenderer renderer = new WaterfallBarRenderer(); // FIXME create a new method for the horizontal version // if (orientation == PlotOrientation.HORIZONTAL) { // ItemLabelPosition position = new ItemLabelPosition( // ItemLabelAnchor.CENTER, TextAnchor.CENTER, // TextAnchor.CENTER, Math.PI / 2.0); // renderer.setBasePositiveItemLabelPosition(position); // renderer.setBaseNegativeItemLabelPosition(position); // } ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0); renderer.setDefaultPositiveItemLabelPosition(position); renderer.setDefaultNegativeItemLabelPosition(position); StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator(); renderer.setDefaultToolTipGenerator(generator); CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.clearRangeMarkers(); Marker baseline = new ValueMarker(0.0); baseline.setPaint(Color.BLACK); plot.addRangeMarker(baseline, Layer.FOREGROUND); JFreeChart chart = new JFreeChart(title, plot); currentTheme.apply(chart); return chart; }