Example usage for org.jfree.chart.renderer.category WaterfallBarRenderer setLastBarPaint

List of usage examples for org.jfree.chart.renderer.category WaterfallBarRenderer setLastBarPaint

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.category WaterfallBarRenderer setLastBarPaint.

Prototype

public void setLastBarPaint(Paint paint) 

Source Link

Document

Sets the paint that will be used to draw the last bar and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java

private static JFreeChart createWaterfallChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createWaterfallChart("Waterfall Chart Demo 1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );// w  w  w. jav  a 2  s . c  o m

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    WaterfallBarRenderer renderer = (WaterfallBarRenderer) plot.getRenderer();

    // set up gradient paints for series...
    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));
    //        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);

    return chart;

}

From source file:org.pentaho.chart.plugin.jfreechart.chart.bar.JFreeWaterfallBarChartGenerator.java

private void setPlotAttributes(CategoryPlot categoryPlot, ChartElement plotElement) {
    WaterfallBarRenderer render = (WaterfallBarRenderer) categoryPlot.getRenderer();
    Paint firstColor = (Paint) plotElement.getLayoutStyle().getValue(ChartStyleKeys.FIRST_BAR_COLOR);
    Paint lastColor = (Paint) plotElement.getLayoutStyle().getValue(ChartStyleKeys.LAST_BAR_COLOR);
    Paint positiveColor = (Paint) plotElement.getLayoutStyle().getValue(ChartStyleKeys.POSITIVE_BAR_COLOR);
    Paint negativeColor = (Paint) plotElement.getLayoutStyle().getValue(ChartStyleKeys.NEGATIVE_BAR_COLOR);
    render.setFirstBarPaint(firstColor);
    render.setLastBarPaint(lastColor);
    render.setPositiveBarPaint(positiveColor);
    render.setNegativeBarPaint(negativeColor);
}

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  w  w  w. j  a v  a2 s. c  o 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.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);
    }//ww w.j  ava2s .  com
    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;

}