Example usage for org.jfree.chart.renderer.category BarRenderer setBase

List of usage examples for org.jfree.chart.renderer.category BarRenderer setBase

Introduction

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

Prototype

public void setBase(double base) 

Source Link

Document

Sets the base value for the bars and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:org.jfree.chart.demo.WaterfallChartDemo1.java

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createWaterfallChart("Product Cost Breakdown", "Expense Category",
            "Cost Per Unit", categorydataset, PlotOrientation.VERTICAL, false, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    categoryplot.setRangeGridlinesVisible(true);
    categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    ValueAxis valueaxis = categoryplot.getRangeAxis();
    DecimalFormat decimalformat = new DecimalFormat("##,###");
    decimalformat.setNegativePrefix("(");
    decimalformat.setNegativeSuffix(")");
    TickUnits tickunits = new TickUnits();
    tickunits.add(new NumberTickUnit(5D, decimalformat));
    tickunits.add(new NumberTickUnit(10D, decimalformat));
    tickunits.add(new NumberTickUnit(20D, decimalformat));
    tickunits.add(new NumberTickUnit(50D, decimalformat));
    tickunits.add(new NumberTickUnit(100D, decimalformat));
    tickunits.add(new NumberTickUnit(200D, decimalformat));
    tickunits.add(new NumberTickUnit(500D, decimalformat));
    tickunits.add(new NumberTickUnit(1000D, decimalformat));
    tickunits.add(new NumberTickUnit(2000D, decimalformat));
    tickunits.add(new NumberTickUnit(5000D, decimalformat));
    valueaxis.setStandardTickUnits(tickunits);
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    barrenderer.setBase(5D);
    DecimalFormat decimalformat1 = new DecimalFormat("$##,###.00");
    decimalformat1.setNegativePrefix("(");
    decimalformat1.setNegativeSuffix(")");
    barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1));
    barrenderer.setBaseItemLabelsVisible(true);
    return jfreechart;
}

From source file:org.tap4j.plugin.util.GraphHelper.java

/**
 * Creates the graph displayed on Method results page to compare execution
 * duration and status of a test method across builds.
 * //  ww  w  .j  a v a  2  s. c o m
 * At max, 9 older builds are displayed.
 * 
 * @param req
 *            request
 * @param dataset
 *            data set to be displayed on the graph
 * @param statusMap
 *            a map with build as key and the test methods execution status
 *            (result) as the value
 * @param methodUrl
 *            URL to get to the method from a build test result page
 * @return the chart
 */
public static JFreeChart createMethodChart(StaplerRequest req, final CategoryDataset dataset,
        final Map<NumberOnlyBuildLabel, String> statusMap, final String methodUrl) {

    final JFreeChart chart = ChartFactory.createBarChart(null, // chart
            // title
            null, // unused
            " Duration (secs)", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            true // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    chart.removeLegend();

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    BarRenderer br = new BarRenderer() {

        private static final long serialVersionUID = 961671076462240008L;
        Map<String, Paint> statusPaintMap = new HashMap<String, Paint>();

        {
            statusPaintMap.put("PASS", ColorPalette.BLUE);
            statusPaintMap.put("SKIP", ColorPalette.YELLOW);
            statusPaintMap.put("FAIL", ColorPalette.RED);
        }

        /**
         * Returns the paint for an item. Overrides the default behavior
         * inherited from AbstractSeriesRenderer.
         * 
         * @param row
         *            the series.
         * @param column
         *            the category.
         * 
         * @return The item color.
         */
        public Paint getItemPaint(final int row, final int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            Paint paint = statusPaintMap.get(statusMap.get(label));
            // when the status of test method is unknown, use gray color
            return paint == null ? Color.gray : paint;
        }
    };

    br.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            if ("UNKNOWN".equals(statusMap.get(label))) {
                return "unknown";
            }
            // values are in seconds
            return dataset.getValue(row, column) + " secs";
        }
    });

    br.setBaseItemURLGenerator(new CategoryURLGenerator() {
        public String generateURL(CategoryDataset dataset, int series, int category) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(category);
            if ("UNKNOWN".equals(statusMap.get(label))) {
                // no link when method result doesn't exist
                return null;
            }
            // return label.build.getUpUrl() + label.build.getNumber() + "/" + PluginImpl.URL + "/" + methodUrl;
            return label.build.getUpUrl() + label.build.getNumber() + "/tap/" + methodUrl;
        }
    });

    br.setItemMargin(0.0);
    br.setMinimumBarLength(5);
    // set the base to be 1/100th of the maximum value displayed in the
    // graph
    br.setBase(br.findRangeBounds(dataset).getUpperBound() / 100);
    plot.setRenderer(br);

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));
    return chart;
}