Example usage for org.jfree.chart ChartFactory createStackedAreaChart

List of usage examples for org.jfree.chart ChartFactory createStackedAreaChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createStackedAreaChart.

Prototype

public static JFreeChart createStackedAreaChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a stacked area chart with default settings.

Usage

From source file:org.tiefaces.components.websheet.chart.ChartHelper.java

/**
 * create stacked area chart.//from  ww w.  j a v  a  2s. c o m
 * 
 * @param chartData
 *            chart data.
 * @return jfree chart.
 */
public JFreeChart createStackedAreaChart(final ChartData chartData) {
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    // create the chart...
    final JFreeChart chart = ChartFactory.createStackedAreaChart(chartData.getTitle(), // chart title
            chartData.getCatAx().getTitle(), // x axis label
            chartData.getValAx().getTitle(), // y axis label
            createDataset(chartData), // data
            orientation, true, // include legend
            false, // tooltips
            false // urls
    );

    setupStyle(chart, chartData);

    return chart;

}

From source file:hudson.tasks.test.AbstractTestResultAction.java

private JFreeChart createChart(StaplerRequest req, CategoryDataset dataset) {

    final String relPath = getRelPath(req);

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title
            null, // unused
            "count", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );//from   ww  w.j  a v  a  2s.  c o  m

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //        legend.setAnchor(StandardLegend.SOUTH);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    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());

    StackedAreaRenderer ar = new StackedAreaRenderer2() {
        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            return relPath + label.getRun().getNumber() + "/testReport/";
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            AbstractTestResultAction a = label.getRun().getAction(AbstractTestResultAction.class);
            switch (row) {
            case 0:
                return String.valueOf(Messages.AbstractTestResultAction_fail(label.getRun().getDisplayName(),
                        a.getFailCount()));
            case 1:
                return String.valueOf(Messages.AbstractTestResultAction_skip(label.getRun().getDisplayName(),
                        a.getSkipCount()));
            default:
                return String.valueOf(Messages.AbstractTestResultAction_test(label.getRun().getDisplayName(),
                        a.getTotalCount()));
            }
        }
    };
    plot.setRenderer(ar);
    ar.setSeriesPaint(0, ColorPalette.RED); // Failures.
    ar.setSeriesPaint(1, ColorPalette.YELLOW); // Skips.
    ar.setSeriesPaint(2, ColorPalette.BLUE); // Total.

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

    return chart;
}

From source file:net.praqma.jenkins.memorymap.MemoryMapBuildAction.java

protected JFreeChart createChart(CategoryDataset dataset, String title, String yaxis, int max, int min) {
    final JFreeChart chart = ChartFactory.createStackedAreaChart(title, // chart                                                                                                                                       // title
            null, // unused
            yaxis, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );// ww w. j av a  2  s  .com

    final LegendTitle legend = chart.getLegend();

    legend.setPosition(RectangleEdge.BOTTOM);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    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());
    rangeAxis.setUpperBound(max);
    rangeAxis.setLowerBound(min);

    final StackedAreaRenderer renderer = (StackedAreaRenderer) plot.getRenderer();
    renderer.setBaseStroke(new BasicStroke(2.0f));
    plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0));
    return chart;
}

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

private static JFreeChart createStackedAreaChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createStackedAreaChart("StackedArea 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 ww. j  a v  a  2s .  com

    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());

    StackedAreaRenderer renderer = (StackedAreaRenderer) plot.getRenderer();
    //        renderer.setRenderAsPercentages(true);

    // 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);

    return chart;

}

From source file:org.adempiere.apps.graph.ChartBuilder.java

private JFreeChart createStackedAreaChart() {
    // create the chart...
    JFreeChart chart = ChartFactory.createStackedAreaChart(chartModel.get_Translation(MChart.COLUMNNAME_Name), // chart title
            chartModel.get_Translation(MChart.COLUMNNAME_DomainLabel), // domain axis label
            chartModel.get_Translation(MChart.COLUMNNAME_RangeLabel), // range axis label
            getCategoryDataset(), // data
            X_AD_Chart.CHARTORIENTATION_Horizontal.equals(chartModel.getChartOrientation())
                    ? PlotOrientation.HORIZONTAL
                    : PlotOrientation.VERTICAL, // orientation
            chartModel.isDisplayLegend(), // include legend
            true, // tooltips?
            true // URLs?
    );//from w w  w.  j a  v  a  2  s. c om

    setupCategoryChart(chart);
    return chart;
}

From source file:hudson.plugins.plot.PlotData.java

/**
 * Creates a Chart of the style indicated by getEffStyle() using the given dataset.
 * Defaults to using createLineChart./*  w w w.j  a  v a  2 s.  com*/
 */
private JFreeChart createChart(PlotCategoryDataset dataset) {
    String s = getUrlStyle();
    if (s.equalsIgnoreCase("area")) {
        return ChartFactory.createAreaChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("bar")) {
        return ChartFactory.createBarChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("bar3d")) {
        return ChartFactory.createBarChart3D(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("line3d")) {
        return ChartFactory.createLineChart3D(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("stackedarea")) {
        return ChartFactory.createStackedAreaChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(),
                dataset, PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("stackedbar")) {
        return ChartFactory.createStackedBarChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(),
                dataset, PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("stackedbar3d")) {
        return ChartFactory.createStackedBarChart3D(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(),
                dataset, PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("waterfall")) {
        return ChartFactory.createWaterfallChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    return ChartFactory.createLineChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
            PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
}

From source file:hudson.plugins.plot.Plot.java

/**
 * Creates a Chart of the style indicated by getEffStyle() using the given
 * dataset. Defaults to using createLineChart.
 *///from ww w . jav  a 2s .c  om
private JFreeChart createChart(PlotCategoryDataset dataset) {
    String s = getUrlStyle();
    if ("area".equalsIgnoreCase(s)) {
        return ChartFactory.createAreaChart(getURLTitle(), /*
                                                            * categoryAxisLabel=
                                                            */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    if ("bar".equalsIgnoreCase(s)) {
        return ChartFactory.createBarChart(getURLTitle(), /*
                                                           * categoryAxisLabel=
                                                           */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    if ("bar3d".equalsIgnoreCase(s)) {
        return ChartFactory.createBarChart3D(getURLTitle(), /*
                                                             * categoryAxisLabel
                                                             * =
                                                             */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    if ("line3d".equalsIgnoreCase(s)) {
        return ChartFactory.createLineChart3D(getURLTitle(), /*
                                                              * categoryAxisLabel
                                                              * =
                                                              */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    if ("lineSimple".equalsIgnoreCase(s)) {
        return ChartFactory.createLineChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }

    if ("stackedarea".equalsIgnoreCase(s)) {
        return ChartFactory.createStackedAreaChart(getURLTitle(), /*
                                                                   * categoryAxisLabel
                                                                   * =
                                                                   */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    if ("stackedbar".equalsIgnoreCase(s)) {
        return ChartFactory.createStackedBarChart(getURLTitle(), /*
                                                                  * categoryAxisLabel
                                                                  * =
                                                                  */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    if ("stackedbar3d".equalsIgnoreCase(s)) {
        return ChartFactory.createStackedBarChart3D(getURLTitle(), /*
                                                                    * categoryAxisLabel
                                                                    * =
                                                                    */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    if ("waterfall".equalsIgnoreCase(s)) {
        return ChartFactory.createWaterfallChart(getURLTitle(), /*
                                                                 * categoryAxisLabel
                                                                 * =
                                                                 */null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*
                                                        * tooltips
                                                        * =
                                                        */
                true, /* url= */false);
    }
    return ChartFactory.createLineChart(getURLTitle(), /* categoryAxisLabel= */
            null, getYaxis(), dataset, PlotOrientation.VERTICAL, hasLegend(), /* tooltips= */true,
            /* url= */false);
}

From source file:hudson.model.Job.java

public Graph getBuildTimeGraph() {
    return new Graph(getLastBuildTime(), 500, 400) {
        @Override//www  .  j av a2s .c  om
        protected JFreeChart createGraph() {
            class ChartLabel implements Comparable<ChartLabel> {
                final Run run;

                public ChartLabel(Run r) {
                    this.run = r;
                }

                public int compareTo(ChartLabel that) {
                    return this.run.number - that.run.number;
                }

                @Override
                public boolean equals(Object o) {
                    // HUDSON-2682 workaround for Eclipse compilation bug
                    // on (c instanceof ChartLabel)
                    if (o == null || !ChartLabel.class.isAssignableFrom(o.getClass())) {
                        return false;
                    }
                    ChartLabel that = (ChartLabel) o;
                    return run == that.run;
                }

                public Color getColor() {
                    // TODO: consider gradation. See
                    // http://www.javadrive.jp/java2d/shape/index9.html
                    Result r = run.getResult();
                    if (r == Result.FAILURE)
                        return ColorPalette.RED;
                    else if (r == Result.UNSTABLE)
                        return ColorPalette.YELLOW;
                    else if (r == Result.ABORTED || r == Result.NOT_BUILT)
                        return ColorPalette.GREY;
                    else
                        return ColorPalette.BLUE;
                }

                @Override
                public int hashCode() {
                    return run.hashCode();
                }

                @Override
                public String toString() {
                    String l = run.getDisplayName();
                    if (run instanceof Build) {
                        String s = ((Build) run).getBuiltOnStr();
                        if (s != null)
                            l += ' ' + s;
                    }
                    return l;
                }

            }

            DataSetBuilder<String, ChartLabel> data = new DataSetBuilder<String, ChartLabel>();
            for (Run r : getNewBuilds()) {
                if (r.isBuilding())
                    continue;
                data.add(((double) r.getDuration()) / (1000 * 60), "min", new ChartLabel(r));
            }

            final CategoryDataset dataset = data.build();

            final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart
                    // title
                    null, // unused
                    Messages.Job_minutes(), // range axis label
                    dataset, // data
                    PlotOrientation.VERTICAL, // orientation
                    false, // include legend
                    true, // tooltips
                    false // urls
            );

            chart.setBackgroundPaint(Color.white);

            final CategoryPlot plot = chart.getCategoryPlot();

            // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
            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();
            ChartUtil.adjustChebyshev(dataset, rangeAxis);
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

            StackedAreaRenderer ar = new StackedAreaRenderer2() {
                @Override
                public Paint getItemPaint(int row, int column) {
                    ChartLabel key = (ChartLabel) dataset.getColumnKey(column);
                    return key.getColor();
                }

                @Override
                public String generateURL(CategoryDataset dataset, int row, int column) {
                    ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
                    return String.valueOf(label.run.number);
                }

                @Override
                public String generateToolTip(CategoryDataset dataset, int row, int column) {
                    ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
                    return label.run.getDisplayName() + " : " + label.run.getDurationString();
                }
            };
            plot.setRenderer(ar);

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

            return chart;
        }
    };
}

From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java

/**
 *
 *//*from   ww  w. j a  v a 2s .  c o  m*/
protected JFreeChart createStackedAreaChart() throws JRException {
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart jfreeChart = ChartFactory.createStackedAreaChart(
            (String) evaluateExpression(getChart().getTitleExpression()),
            (String) evaluateExpression(((JRAreaPlot) getPlot()).getCategoryAxisLabelExpression()),
            (String) evaluateExpression(((JRAreaPlot) getPlot()).getValueAxisLabelExpression()),
            (CategoryDataset) getDataset(), getPlot().getOrientation(), isShowLegend(), true, false);

    configureChart(jfreeChart, getPlot());
    JRAreaPlot areaPlot = (JRAreaPlot) getPlot();

    // Handle the axis formating for the category axis
    configureAxis(((CategoryPlot) jfreeChart.getPlot()).getDomainAxis(), areaPlot.getCategoryAxisLabelFont(),
            areaPlot.getCategoryAxisLabelColor(), areaPlot.getCategoryAxisTickLabelFont(),
            areaPlot.getCategoryAxisTickLabelColor(), areaPlot.getCategoryAxisTickLabelMask(),
            areaPlot.getCategoryAxisVerticalTickLabels(), areaPlot.getOwnCategoryAxisLineColor(), false,
            (Comparable) evaluateExpression(areaPlot.getDomainAxisMinValueExpression()),
            (Comparable) evaluateExpression(areaPlot.getDomainAxisMaxValueExpression()));

    // Handle the axis formating for the value axis
    configureAxis(((CategoryPlot) jfreeChart.getPlot()).getRangeAxis(), areaPlot.getValueAxisLabelFont(),
            areaPlot.getValueAxisLabelColor(), areaPlot.getValueAxisTickLabelFont(),
            areaPlot.getValueAxisTickLabelColor(), areaPlot.getValueAxisTickLabelMask(),
            areaPlot.getValueAxisVerticalTickLabels(), areaPlot.getOwnValueAxisLineColor(), true,
            (Comparable) evaluateExpression(areaPlot.getRangeAxisMinValueExpression()),
            (Comparable) evaluateExpression(areaPlot.getRangeAxisMaxValueExpression()));

    ((CategoryPlot) jfreeChart.getPlot()).getDomainAxis().setCategoryMargin(0);

    return jfreeChart;
}