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:hudson.plugins.emma.portlet.chart.EmmaBuilderTrendChart.java

/**
 * Creates a graph for Emma Coverage results.
 *
 * @param summaries/*from  w  w w  .  j  a  v a  2 s.c o  m*/
 *          HashMap(key = run date and value = Instrumentation tests
 *          results)
 * @param widthParam
 *          the chart width
 * @param heightParam
 *          the chart height
 * @return Graph (JFreeChart)
 */
private static Graph createTrendChart(final Map<LocalDate, EmmaCoverageResultSummary> summaries, int widthParam,
        int heightParam) {

    return new Graph(-1, widthParam, heightParam) {

        @Override
        protected JFreeChart createGraph() {

            // Show empty chart
            if (summaries == null) {
                JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL,
                        Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false);

                return chart;
            }

            int lineNumber = 0;

            JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL,
                    Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false,
                    false);

            chart.setBackgroundPaint(Color.white);

            CategoryPlot plot = chart.getCategoryPlot();

            // Line thickness
            CategoryItemRenderer renderer = plot.getRenderer();
            BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND,
                    BasicStroke.JOIN_ROUND);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber, stroke);

            plot.setBackgroundPaint(Color.WHITE);
            plot.setOutlinePaint(null);
            plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA);
            plot.setRangeGridlinesVisible(true);
            plot.setRangeGridlinePaint(Color.black);

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

            NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            rangeAxis.setUpperBound(Constants.UPPER_BOUND);
            rangeAxis.setLowerBound(Constants.LOWER_BOUND);

            return chart;

        }
    };
}

From source file:hudson.plugins.karma.portlet.chart.KarmaBuilderTrendChart.java

/**
 * Creates a graph for Karma Coverage results.
 *
 * @param summaries/*ww  w .ja v a  2s .c  o  m*/
 *          HashMap(key = run date and value = Instrumentation tests
 *          results)
 * @param widthParam
 *          the chart width
 * @param heightParam
 *          the chart height
 * @return Graph (JFreeChart)
 */
private static Graph createTrendChart(final Map<LocalDate, KarmaCoverageResultSummary> summaries,
        int widthParam, int heightParam) {

    return new Graph(-1, widthParam, heightParam) {

        @Override
        protected JFreeChart createGraph() {

            // Show empty chart
            if (summaries == null) {
                JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL,
                        Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false);

                return chart;
            }

            int lineNumber = 0;

            JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL,
                    Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false,
                    false);

            chart.setBackgroundPaint(Color.white);

            CategoryPlot plot = chart.getCategoryPlot();

            // Line thickness
            CategoryItemRenderer renderer = plot.getRenderer();
            BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND,
                    BasicStroke.JOIN_ROUND);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber, stroke);

            plot.setBackgroundPaint(Color.WHITE);
            plot.setOutlinePaint(null);
            plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA);
            plot.setRangeGridlinesVisible(true);
            plot.setRangeGridlinePaint(Color.black);

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

            NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            rangeAxis.setUpperBound(Constants.UPPER_BOUND);
            rangeAxis.setLowerBound(Constants.LOWER_BOUND);

            return chart;

        }
    };
}

From source file:hudson.plugins.jacoco.portlet.chart.JacocoBuilderTrendChart.java

/**
 * Creates a graph for JaCoCo Coverage results.
 *
 * @param summaries// w w  w  . j  a  va2s  .  c  o  m
 *          HashMap(key = run date and value = Instrumentation tests
 *          results)
 * @param widthParam
 *          the chart width
 * @param heightParam
 *          the chart height
 * @return Graph (JFreeChart)
 */
private static Graph createTrendChart(final Map<LocalDate, JacocoCoverageResultSummary> summaries,
        int widthParam, int heightParam) {

    return new Graph(-1, widthParam, heightParam) {

        @Override
        protected JFreeChart createGraph() {

            // Show empty chart
            if (summaries == null) {
                JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL,
                        Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false);

                return chart;
            }

            int lineNumber = 0;

            JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL,
                    Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false,
                    false);

            chart.setBackgroundPaint(Color.white);

            CategoryPlot plot = chart.getCategoryPlot();

            // Line thickness
            CategoryItemRenderer renderer = plot.getRenderer();
            BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND,
                    BasicStroke.JOIN_ROUND);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber, stroke);

            plot.setBackgroundPaint(Color.WHITE);
            plot.setOutlinePaint(null);
            plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA);
            plot.setRangeGridlinesVisible(true);
            plot.setRangeGridlinePaint(Color.black);

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

            NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            //rangeAxis.setUpperBound(Constants.UPPER_BOUND);
            rangeAxis.setLowerBound(Constants.LOWER_BOUND);

            return chart;

        }
    };
}

From source file:hudson.plugins.codecover.portlet.chart.CodeCoverBuilderTrendChart.java

/**
 * Creates a graph for CodeCover Coverage results.
 *
 * @param summaries// w  w  w. ja  v  a  2 s  .  c o m
 *          HashMap(key = run date and value = Instrumentation tests
 *          results)
 * @param widthParam
 *          the chart width
 * @param heightParam
 *          the chart height
 * @return Graph (JFreeChart)
 */
private static Graph createTrendChart(final Map<LocalDate, CodeCoverCoverageResultSummary> summaries,
        int widthParam, int heightParam) {

    return new Graph(-1, widthParam, heightParam) {

        @Override
        protected JFreeChart createGraph() {

            // Show empty chart
            if (summaries == null) {
                JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL,
                        Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false);

                return chart;
            }

            int lineNumber = 0;

            JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL,
                    Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false,
                    false);

            chart.setBackgroundPaint(Color.white);

            CategoryPlot plot = chart.getCategoryPlot();

            // Line thickness
            CategoryItemRenderer renderer = plot.getRenderer();
            BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND,
                    BasicStroke.JOIN_ROUND);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber, stroke);

            plot.setBackgroundPaint(Color.WHITE);
            plot.setOutlinePaint(null);
            plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA);
            plot.setRangeGridlinesVisible(true);
            plot.setRangeGridlinePaint(Color.black);

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

            NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            rangeAxis.setUpperBound(Constants.UPPER_BOUND);
            rangeAxis.setLowerBound(Constants.LOWER_BOUND);

            return chart;

        }
    };
}

From source file:org.exist.xquery.modules.jfreechart.JFreeChartFactory.java

/**
 *  Create JFreeChart graph using the supplied parameters.
 *
 * @param chartType One of the many chart types.
 * @param conf      Chart configuration//from  w  w  w.  ja v  a  2s .  com
 * @param is        Inputstream containing chart data
 * @return          Initialized chart or NULL in case of issues.
 * @throws IOException Thrown when a problem is reported while parsing XML data.
 */
public static JFreeChart createJFreeChart(String chartType, Configuration conf, InputStream is)
        throws XPathException {

    logger.debug("Generating " + chartType);

    // Currently two dataset types supported
    CategoryDataset categoryDataset = null;
    PieDataset pieDataset = null;

    try {
        if ("PieChart".equals(chartType) || "PieChart3D".equals(chartType) || "RingChart".equals(chartType)) {
            logger.debug("Reading XML PieDataset");
            pieDataset = DatasetReader.readPieDatasetFromXML(is);

        } else {
            logger.debug("Reading XML CategoryDataset");
            categoryDataset = DatasetReader.readCategoryDatasetFromXML(is);
        }

    } catch (IOException ex) {
        throw new XPathException(ex.getMessage());

    } finally {
        try {
            is.close();
        } catch (IOException ex) {
            //
        }
    }

    // Return chart
    JFreeChart chart = null;

    // Big chart type switch
    if ("AreaChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createAreaChart(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("BarChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createBarChart(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("BarChart3D".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createBarChart3D(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("LineChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createLineChart(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("LineChart3D".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createLineChart3D(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("MultiplePieChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createMultiplePieChart(conf.getTitle(), categoryDataset, conf.getOrder(),
                conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls());

        setPieChartParameters(chart, conf);

    } else if ("MultiplePieChart3D".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createMultiplePieChart3D(conf.getTitle(), categoryDataset, conf.getOrder(),
                conf.isGenerateLegend(), conf.isGenerateTooltips(), conf.isGenerateUrls());

        setPieChartParameters(chart, conf);

    } else if ("PieChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createPieChart(conf.getTitle(), pieDataset, conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setPieChartParameters(chart, conf);

    } else if ("PieChart3D".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createPieChart3D(conf.getTitle(), pieDataset, conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setPieChartParameters(chart, conf);

    } else if ("RingChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createRingChart(conf.getTitle(), pieDataset, conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setPieChartParameters(chart, conf);
    } else if ("SpiderWebChart".equalsIgnoreCase(chartType)) {
        SpiderWebPlot plot = new SpiderWebPlot(categoryDataset);
        if (conf.isGenerateTooltips()) {
            plot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
        }
        chart = new JFreeChart(conf.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, false);

        if (conf.isGenerateLegend()) {
            LegendTitle legend = new LegendTitle(plot);
            legend.setPosition(RectangleEdge.BOTTOM);
            chart.addSubtitle(legend);
        } else {
            TextTitle subTitle = new TextTitle(" ");
            subTitle.setPosition(RectangleEdge.BOTTOM);
            chart.addSubtitle(subTitle);
        }

        setCategoryChartParameters(chart, conf);

    } else if ("StackedAreaChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createStackedAreaChart(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("StackedBarChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createStackedBarChart(conf.getTitle(), conf.getDomainAxisLabel(),
                conf.getRangeAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("StackedBarChart3D".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createStackedBarChart3D(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);

    } else if ("WaterfallChart".equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createWaterfallChart(conf.getTitle(), conf.getCategoryAxisLabel(),
                conf.getValueAxisLabel(), categoryDataset, conf.getOrientation(), conf.isGenerateLegend(),
                conf.isGenerateTooltips(), conf.isGenerateUrls());

        setCategoryChartParameters(chart, conf);
    } else {
        logger.error("Illegal chartype. Choose one of " + "AreaChart BarChart BarChart3D LineChart LineChart3D "
                + "MultiplePieChart MultiplePieChart3D PieChart PieChart3D "
                + "RingChart SpiderWebChart StackedAreaChart StackedBarChart "
                + "StackedBarChart3D WaterfallChart");
    }

    setCommonParameters(chart, conf);

    return chart;
}

From source file:com.mentor.questa.vrm.jenkins.QuestaVrmHostAction.java

private JFreeChart createChart(StaplerRequest req, CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title
            "Relative time", // unused
            "count", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );/*from  ww w  . java  2  s  .co m*/

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);

    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() {
        private long getTime(CategoryDataset dataset, int column) {
            Long offset = (Long) dataset.getColumnKey(column);
            return getRegressionResult().getRegressionBegin().getTime() + offset * 1000;

        }

        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            return "javascript:getSummary(" + getTime(dataset, column) + ");";
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            String host = (String) dataset.getRowKey(row);
            Date date = new Date(getTime(dataset, column));
            int value = (Integer) dataset.getValue(row, column);
            return value + " on " + host + "@" + date.toString();
        }
    };
    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.jsfcomp.chartcreator.utils.ChartUtils.java

public static JFreeChart createChartWithCategoryDataSet(ChartData chartData) {
    JFreeChart chart = null;// www.j a va  2  s  . c  o m
    PlotOrientation plotOrientation = ChartUtils.getPlotOrientation(chartData.getOrientation());

    CategoryDataset dataset = (CategoryDataset) chartData.getDatasource();
    String type = chartData.getType();
    String xAxis = chartData.getXlabel();
    String yAxis = chartData.getYlabel();
    boolean is3d = chartData.isChart3d();
    boolean legend = chartData.isLegend();

    if (type.equalsIgnoreCase("bar")) {
        if (is3d == true) {
            chart = ChartFactory.createBarChart3D("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        } else {
            chart = ChartFactory.createBarChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        }
        setBarOutline(chart, chartData);
    } else if (type.equalsIgnoreCase("stackedbar")) {
        if (is3d == true) {
            chart = ChartFactory.createStackedBarChart3D("", xAxis, yAxis, dataset, plotOrientation, legend,
                    true, false);
        } else {
            chart = ChartFactory.createStackedBarChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        }
        setBarOutline(chart, chartData);
    } else if (type.equalsIgnoreCase("line")) {
        if (is3d == true)
            chart = ChartFactory.createLineChart3D("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
        else
            chart = ChartFactory.createLineChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                    false);
    } else if (type.equalsIgnoreCase("area")) {
        chart = ChartFactory.createAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("stackedarea")) {
        chart = ChartFactory.createStackedAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                false);
    } else if (type.equalsIgnoreCase("waterfall")) {
        chart = ChartFactory.createWaterfallChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                false);
    } else if (type.equalsIgnoreCase("gantt")) {
        chart = ChartFactory.createGanttChart("", xAxis, yAxis, (IntervalCategoryDataset) dataset, legend, true,
                false);
    }

    CategoryPlot plot = (CategoryPlot) chart.getCategoryPlot();
    plot.setDomainGridlinesVisible(chartData.isDomainGridLines());
    plot.setRangeGridlinesVisible(chartData.isRangeGridLines());
    if (chartData.getGenerateMap() != null)
        plot.getRenderer().setBaseItemURLGenerator(new StandardCategoryURLGenerator(""));

    int seriesCount = plot.getDataset().getColumnCount();
    if (chartData.getLineStokeWidth() > 0) {
        for (int index = 0; index <= seriesCount; index++)
            plot.getRenderer().setSeriesStroke(index, new BasicStroke(chartData.getLineStokeWidth()));
    }

    setCategorySeriesColors(chart, chartData);

    setCategoryExtensions(chart, chartData);

    return chart;
}

From source file:org.korosoft.hudson.plugin.dynamic.CukeTestResultChartAction.java

private JFreeChart createChart(List<ChartBuildEntry> history) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    String seriesFailed = "Failed";
    String seriesPassed = "Passed";
    String seriesRegression = "Failed [Regression]";
    String seriesImprovement = "Passed [Improvement]";

    dataset.setValue(0, seriesFailed, "0");
    dataset.setValue(0, seriesRegression, "0");
    dataset.setValue(0, seriesImprovement, "0");
    dataset.setValue(0, seriesPassed, "0");
    dataset.removeColumn(0);// ww w  . jav  a  2 s .  c om

    for (ChartBuildEntry entry : history) {
        final String buildLabel = Integer.toString(entry.buildNo);
        dataset.setValue(entry.failed, seriesFailed, buildLabel);
        dataset.setValue(entry.regressed, seriesRegression, buildLabel);
        dataset.setValue(entry.improved, seriesImprovement, buildLabel);
        dataset.setValue(entry.passed, seriesPassed, buildLabel);
    }

    JFreeChart chart = ChartFactory.createStackedAreaChart(null, "Build #", "Number of scenarios", dataset,
            PlotOrientation.VERTICAL, true, true, true);
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.getDomainAxis().setAxisLineVisible(false);
    plot.getDomainAxis().setCategoryMargin(0);
    plot.getDomainAxis().setUpperMargin(0);
    plot.getDomainAxis().setLowerMargin(0);
    plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    plot.getRenderer().setSeriesPaint(0, new Color(0xFF8080));
    plot.getRenderer().setSeriesPaint(1, new Color(0xFF0000));
    plot.getRenderer().setSeriesPaint(2, new Color(0x0000C0));
    plot.getRenderer().setSeriesPaint(3, new Color(0x8080FF));
    return chart;
}

From source file:no.uio.medicine.virsurveillance.charts.StackedChart_AWT.java

public void updateChartData() {
    this.printable = false;
    if (dataPoints.size() != xAxis.size() && dataPoints.size() != titles.size()) {
        System.out.println("Error: Data size not match");
    }//from   ww w .j  ava2  s.c  om

    JFreeChart stackedChart = ChartFactory.createStackedAreaChart(chartTitle, this.yAxisTitle, this.xAxisTitle,
            createDataset(this.dataPoints, this.xAxis, this.titles), PlotOrientation.VERTICAL, true, true,
            false);
    stackedChart.setBackgroundPaint(Color.white);

    this.chartPanel = new ChartPanel(stackedChart);
    this.chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
    this.plot = (CategoryPlot) stackedChart.getPlot();
    this.renderer = plot.getRenderer();

    for (int i = 0; i < this.dataPoints.size(); i++) {
        plot.getRenderer().setSeriesPaint(i, getColor(i));
    }
    plot.getRenderer().setItemLabelsVisible(true);

    //renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    //renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    //renderer.setSeriesStroke(2, new BasicStroke(2.0f));
    setContentPane(this.chartPanel);

    this.pack();
    this.setVisible(true);
    this.printable = true;

}

From source file:de.laures.cewolf.taglib.CewolfChartFactory.java

public static JFreeChart getChartInstance(String chartType, String title, String xAxisLabel, String yAxisLabel,
        Dataset data) throws ChartValidationException {
    // first check the dynamically registered chart types
    CewolfChartFactory factory = (CewolfChartFactory) factories.get(chartType);
    if (factory != null) {
        // custom factory found, use it
        return factory.getChartInstance(title, xAxisLabel, yAxisLabel, data);
    }/*from  w w w.  j ava  2 s  .c  o  m*/

    switch (getChartTypeConstant(chartType)) {
    case XY:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, (XYDataset) data,
                PlotOrientation.VERTICAL, true, true, true);
    case PIE:
        check(data, PieDataset.class, chartType);
        return ChartFactory.createPieChart(title, (PieDataset) data, true, true, true);
    case AREA_XY:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createXYAreaChart(title, xAxisLabel, yAxisLabel, (XYDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case SCATTER:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, (XYDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case AREA:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case HORIZONTAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.HORIZONTAL, true, false, false);
    case HORIZONTAL_BAR_3D:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.HORIZONTAL, true, false, false);
    case LINE:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case STACKED_HORIZONTAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.HORIZONTAL, true, false, false);
    case STACKED_VERTICAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case STACKED_VERTICAL_BAR_3D:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case VERTICAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case VERTICAL_BAR_3D:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case TIME_SERIES:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createTimeSeriesChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, true, false,
                false);
    case CANDLE_STICK:
        check(data, OHLCDataset.class, chartType);
        return ChartFactory.createCandlestickChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true);
    case HIGH_LOW:
        check(data, OHLCDataset.class, chartType);
        return ChartFactory.createHighLowChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true);
    case GANTT:
        check(data, IntervalCategoryDataset.class, chartType);
        return ChartFactory.createGanttChart(title, xAxisLabel, yAxisLabel, (IntervalCategoryDataset) data,
                true, false, false);
    case WIND:
        check(data, WindDataset.class, chartType);
        return ChartFactory.createWindPlot(title, xAxisLabel, yAxisLabel, (WindDataset) data, true, false,
                false);
    //case SIGNAL :
    //  check(data, SignalsDataset.class, chartType);
    //  return ChartFactory.createSignalChart(title, xAxisLabel, yAxisLabel, (SignalsDataset) data, true);
    case VERRTICAL_XY_BAR:
        check(data, IntervalXYDataset.class, chartType);
        return ChartFactory.createXYBarChart(title, xAxisLabel, true, yAxisLabel, (IntervalXYDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case PIE_3D:
        check(data, PieDataset.class, chartType);
        return ChartFactory.createPieChart3D(title, (PieDataset) data, true, false, false);
    case METER:
        check(data, ValueDataset.class, chartType);
        MeterPlot plot = new MeterPlot((ValueDataset) data);
        JFreeChart chart = new JFreeChart(title, plot);
        return chart;
    case STACKED_AREA:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case BUBBLE:
        check(data, XYZDataset.class, chartType);
        return ChartFactory.createBubbleChart(title, xAxisLabel, yAxisLabel, (XYZDataset) data,
                PlotOrientation.VERTICAL, true, false, false);

    case AUSTER_CICLOS:
        check(data, IntervalCategoryDataset.class, chartType);
        return ChartFactory.createAusterCiclosChart((IntervalCategoryDataset) data);

    default:
        throw new UnsupportedChartTypeException(chartType + " is not supported.");
    }
}