Example usage for org.jfree.chart ChartFactory createAreaChart

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

Introduction

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

Prototype

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

Source Link

Document

Creates an area chart with default settings.

Usage

From source file:com.thecoderscorner.groovychart.chart.AreaChart.java

public JFreeChart createChart() {
    JFreeChart chart = ChartFactory.createAreaChart(getTitle(), getCategoryAxisLabel(), getValueAxisLabel(),
            (CategoryDataset) getDataset(), getOrientation(), isLegend(), isTooltips(), isUrls());
    return setExtraProperties(chart);

}

From source file:com.mergano.core.AreaChart.java

private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createAreaChart("Order statistic", // chart title
            "Days", // domain axis label
            "Order Average", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            false, // tooltips
            false // urls
    );// ww w  .ja  v  a  2 s .  c om

    // 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);
    chart.setAntiAlias(true);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.getRenderer().setSeriesPaint(0, new Color(0, 191, 165));
    plot.setForegroundAlpha(0.75f);
    plot.setBackgroundPaint(Color.white);

    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); // disable this
    plot.setDomainGridlinesVisible(false);
    plot.setDomainGridlinePaint(new Color(240, 240, 240));
    plot.setRangeGridlinesVisible(false);
    plot.setRangeGridlinePaint(new Color(240, 240, 240));
    plot.setDomainCrosshairPaint(Color.MAGENTA);
    plot.setRangeCrosshairPaint(Color.CYAN);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.addCategoryLabelToolTip("Type 1", "The first type.");
    domainAxis.addCategoryLabelToolTip("Type 2", "The second type.");
    domainAxis.addCategoryLabelToolTip("Type 3", "The third type.");

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLabelAngle(0 * Math.PI / 2.0);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:com.kiyoshi.gui.AreaChart.java

private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );//from   ww  w  . j a va 2  s .co 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.setForegroundAlpha(0.5f);

    //      plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.addCategoryLabelToolTip("Type 1", "The first type.");
    domainAxis.addCategoryLabelToolTip("Type 2", "The second type.");
    domainAxis.addCategoryLabelToolTip("Type 3", "The third type.");

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLabelAngle(0 * Math.PI / 2.0);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:com.manydesigns.portofino.chart.ChartAreaGenerator.java

protected JFreeChart createChart(ChartDefinition chartDefinition, CategoryDataset dataset,
        PlotOrientation plotOrientation) {
    return ChartFactory.createAreaChart(chartDefinition.getName(), chartDefinition.getXAxisName(),
            chartDefinition.getYAxisName(), dataset, plotOrientation, true, true, true);
}

From source file:org.operamasks.faces.render.graph.AreaChartRenderer.java

protected JFreeChart createChart(UIChart comp) {
    Dataset dataset = createDataset(comp);
    JFreeChart chart = null;/*ww  w.j a v a  2s  .  c o  m*/

    if (dataset instanceof CategoryDataset) {
        if (comp.isStacked()) {
            chart = ChartFactory.createStackedAreaChart(null, null, null, (CategoryDataset) dataset,
                    getChartOrientation(comp), false, false, false);
        } else {
            chart = ChartFactory.createAreaChart(null, null, null, (CategoryDataset) dataset,
                    getChartOrientation(comp), false, false, false);
        }
    } else if (dataset instanceof XYDataset) {
        chart = ChartFactory.createXYAreaChart(null, null, null, (XYDataset) dataset, getChartOrientation(comp),
                false, false, false);

        if (dataset instanceof TimeSeriesCollection) {
            DateAxis xAxis = new DateAxis(null);
            xAxis.setLowerMargin(0.02);
            xAxis.setUpperMargin(0.02);
            ((XYPlot) chart.getPlot()).setDomainAxis(xAxis);
        }
    }

    return chart;
}

From source file:unikn.dbis.univis.visualization.chart.AreaChart.java

/**
 * Returns the JFreeChart./*ww  w.  jav  a  2s .  com*/
 *
 * @return JFreeChart.
 */
protected JFreeChart createChart() {
    return ChartFactory.createAreaChart(getChartName(), "", xAxis, getDataset(), PlotOrientation.VERTICAL, true,
            false, false);
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createAreaChart("Area Chart", "Category", "Value", categorydataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    TextTitle texttitle = new TextTitle(
            "An area chart demonstration.  We use this subtitle as an example of what happens when you get a really long title or subtitle.");
    texttitle.setFont(new Font("SansSerif", 0, 12));
    texttitle.setPosition(RectangleEdge.TOP);
    texttitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.050000000000000003D, 0.050000000000000003D,
            0.050000000000000003D, 0.050000000000000003D));
    texttitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
    jfreechart.addSubtitle(texttitle);/*  w  ww.  ja v  a 2  s.  c o  m*/
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setForegroundAlpha(0.5F);
    categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinesVisible(true);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinesVisible(true);
    categoryplot.setRangeGridlinePaint(Color.white);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    categoryaxis.setLowerMargin(0.0D);
    categoryaxis.setUpperMargin(0.0D);
    categoryaxis.addCategoryLabelToolTip("Type 1", "The first type.");
    categoryaxis.addCategoryLabelToolTip("Type 2", "The second type.");
    categoryaxis.addCategoryLabelToolTip("Type 3", "The third type.");
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setLabelAngle(0.0D);
    return jfreechart;
}

From source file:com.liferay.portlet.polls.action.ViewChartAction.java

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    try {//  w  ww .  j av a  2  s .c  om
        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

        long questionId = ParamUtil.getLong(request, "questionId");

        String chartType = ParamUtil.getString(request, "chartType", "pie");

        CategoryDataset dataset = PollsUtil.getVotesDataset(questionId);

        String chartName = themeDisplay.translate("vote-results");
        String xName = themeDisplay.translate("choice");
        String yName = themeDisplay.translate("votes");

        JFreeChart chart = null;

        if (chartType.equals("area")) {
            chart = ChartFactory.createAreaChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL,
                    true, false, false);
        } else if (chartType.equals("horizontal_bar")) {
            chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.HORIZONTAL,
                    true, false, false);
        } else if (chartType.equals("line")) {
            chart = ChartFactory.createLineChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL,
                    true, false, false);
        } else if (chartType.equals("vertical_bar")) {
            chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL,
                    true, false, false);
        } else {
            PieDataset pieData = DatasetUtilities.createPieDatasetForRow(dataset, 0);

            chart = ChartFactory.createPieChart(chartName, pieData, true, false, false);
        }

        response.setContentType(ContentTypes.IMAGE_JPEG);

        OutputStream os = response.getOutputStream();

        ChartUtilities.writeChartAsJPEG(os, chart, 400, 400);

        return null;
    } catch (Exception e) {
        PortalUtil.sendError(e, request, response);

        return null;
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.AreaChartExpression.java

protected JFreeChart computeCategoryChart(final CategoryDataset categoryDataset) {
    final PlotOrientation orientation = computePlotOrientation();
    final JFreeChart chart;
    if (isStacked()) {
        chart = createStackedAreaChart(computeTitle(), getCategoryAxisLabel(), getValueAxisLabel(),
                categoryDataset, orientation, isShowLegend(), false, false);
    } else {/*w w  w.ja v a 2s .co m*/
        chart = ChartFactory.createAreaChart(computeTitle(), getCategoryAxisLabel(), getValueAxisLabel(),
                categoryDataset, orientation, isShowLegend(), false, false);
        chart.getCategoryPlot().setDomainAxis(new FormattedCategoryAxis(getCategoryAxisLabel(),
                getCategoricalAxisMessageFormat(), getRuntime().getResourceBundleFactory().getLocale()));
    }

    configureLogarithmicAxis(chart.getCategoryPlot());
    return chart;
}

From source file:net.sourceforge.processdash.ui.web.reports.AreaChart.java

/** Create a line chart. */
public JFreeChart createChart() {
    JFreeChart chart;/*ww w  .  j a v a  2 s  . c o  m*/
    CategoryDataset catData = data.catDataSource();

    Object stacked = parameters.get("stacked");
    if (stacked != null) {
        chart = ChartFactory.createStackedAreaChart(null, null, null, catData, PlotOrientation.VERTICAL, true,
                true, false);
        if ("pct".equals(stacked)) {
            ((StackedAreaRenderer) chart.getCategoryPlot().getRenderer()).setRenderAsPercentages(true);
            DecimalFormat fmt = new DecimalFormat();
            fmt.setMultiplier(100);
            ((NumberAxis) chart.getCategoryPlot().getRangeAxis()).setNumberFormatOverride(fmt);
            if (parameters.get("units") == null)
                parameters.put("units", "%");
        }

    } else {
        chart = ChartFactory.createAreaChart(null, null, null, catData, PlotOrientation.VERTICAL, true, true,
                false);
    }

    setupCategoryChart(chart);

    Object colorScheme = parameters.get("colorScheme");
    if ("consistent".equals(colorScheme))
        configureConsistentColors(chart.getCategoryPlot(), catData);
    else if (parameters.containsKey("c1"))
        configureIndividualColors(chart.getCategoryPlot(), catData);

    return chart;
}