Example usage for org.jfree.chart ChartFactory createStackedXYAreaChart

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

Introduction

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

Prototype

public static JFreeChart createStackedXYAreaChart(String title, String xAxisLabel, String yAxisLabel,
        TableXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a stacked XY area plot.

Usage

From source file:com.bpd.jfreechart.StackedAreaChartDemo.java

/**
 * Test program that will display a JFreeChart showing interpolated data points.
 * /* ww  w  . j a v  a  2  s .c o m*/
 * @param args <b>"1"</b> to display Series 1. <b>"2"</b> to display Series 2. <b>"0"</b> to
 * display both series.
 */
public static void main(String... args) {
    // Check arguments.
    if (args.length != 1) {
        System.err.println("Usage: java Chart [0|1|2]\n\n  -- 0: Display Series 1.");
        System.err.println("  -- 1: Display Series 2.\n  -- 2: Display both series.");
        return;
    }

    String option = args[0];
    if (!"0".equals(option) && !"1".equals(option) && !"2".equals(option)) {
        System.err.println("Invalid argument: " + option);
        return;
    }

    // Create some sample data.
    List<Point<Number, Number>> list1 = new ArrayList<Point<Number, Number>>();
    list1.add(new Point<Number, Number>(50, 100.0));
    list1.add(new Point<Number, Number>(150, 100));
    list1.add(new Point<Number, Number>(250, 200));
    list1.add(new Point<Number, Number>(350, 400));
    list1.add(new Point<Number, Number>(450, 200));
    list1.add(new Point<Number, Number>(550, 100));

    List<Point<Number, Number>> list2 = new ArrayList<Point<Number, Number>>();
    list2.add(new Point<Number, Number>(50, 100.0));
    list2.add(new Point<Number, Number>(150, 200.0));
    list2.add(new Point<Number, Number>(250, 400.0));
    list2.add(new Point<Number, Number>(350, 600.0));
    list2.add(new Point<Number, Number>(450, 400.0));
    list2.add(new Point<Number, Number>(550, 200.0));

    // Add data to time series.
    TimeSeries series1 = new TimeSeries("Series 1", FixedMillisecond.class);
    for (Point<Number, Number> dataPoint : list1) {
        if ("1".equals(option) || "0".equals(option)) {
            series1.add(new FixedMillisecond(dataPoint.getX().longValue()), dataPoint.getY());
        }
        series1.setDescription("Series 1");
    }

    TimeSeries series2 = new TimeSeries("Series 2", FixedMillisecond.class);
    for (Point<Number, Number> dataPoint : list2) {
        if ("2".equals(option) || "0".equals(option)) {
            series2.add(new FixedMillisecond(dataPoint.getX().longValue()), dataPoint.getY());
        }
        series2.setDescription("Series 2");
    }

    TimeSeriesCollection collection = new TimeSeriesCollection();
    if ("1".equals(option)) {
        collection.addSeries(series1);
    } else if ("2".equals(option)) {
        collection.addSeries(series2);
    } else if ("0".equals(option)) {
        collection.addSeries(series1);
        collection.addSeries(series2);
    }

    TimeTableXYDataset dataset = new TimeTableXYDataset();
    @SuppressWarnings("unchecked")
    List<TimeSeries> timeSeriesList = collection.getSeries();
    for (TimeSeries t : timeSeriesList) {
        for (int index = 0; index < t.getItemCount(); index++) {
            TimeSeriesDataItem dataItem = (TimeSeriesDataItem) t.getItems().get(index);
            dataset.add(t.getTimePeriod(index), dataItem.getValue().doubleValue(), t.getDescription());
        }
    }

    // Create and display chart.
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(null, null, null, dataset,
            PlotOrientation.VERTICAL, false, true, false);

    customizeChart(chart);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));

    JFrame frame = new JFrame();
    frame.getContentPane().add(chartPanel);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

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

private static JFreeChart createChart(TableXYDataset tablexydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedXYAreaChart("Stacked XY Area Chart Demo 1", "X Value",
            "Y Value", tablexydataset, PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    StackedXYAreaRenderer stackedxyarearenderer = new StackedXYAreaRenderer();
    stackedxyarearenderer.setSeriesPaint(0, Color.lightGray);
    stackedxyarearenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    xyplot.setRenderer(0, stackedxyarearenderer);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    return jfreechart;
}

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

private static JFreeChart createChart(TableXYDataset tablexydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedXYAreaChart("StackedXYAreaRendererDemo1", "X Value",
            "Y Value", tablexydataset, PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    StackedXYAreaRenderer stackedxyarearenderer = new StackedXYAreaRenderer(5);
    stackedxyarearenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    xyplot.setRenderer(0, stackedxyarearenderer);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    stackedxyarearenderer.setShapePaint(Color.yellow);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

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

public JFreeChart createChart() {
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(getTitle(), getXAxisLabel(), getYAxisLabel(),
            (TableXYDataset) getDataset(), getOrientation(), isLegend(), isTooltips(), isUrls());
    return setExtraProperties(chart);

}

From source file:org.matsim.contrib.util.timeprofile.TimeProfileCharts.java

public static JFreeChart chartProfile(DefaultTableXYDataset dataset, ChartType type) {
    JFreeChart chart;/*from   w w w  .j av a  2s  .c o  m*/
    switch (type) {
    case Line:
        chart = ChartFactory.createXYLineChart("TimeProfile", "Time [h]", "Values", dataset,
                PlotOrientation.VERTICAL, true, false, false);
        break;

    case StackedArea:
        chart = ChartFactory.createStackedXYAreaChart("TimeProfile", "Time [h]", "Values", dataset,
                PlotOrientation.VERTICAL, true, false, false);
        break;

    default:
        throw new IllegalArgumentException();
    }

    XYPlot plot = chart.getXYPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setBackgroundPaint(Color.white);

    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRange(true);

    XYItemRenderer renderer = plot.getRenderer();
    for (int s = 0; s < dataset.getSeriesCount(); s++) {
        renderer.setSeriesStroke(s, new BasicStroke(2));
    }

    return chart;
}

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

private static JFreeChart createChart(TableXYDataset tablexydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedXYAreaChart("Stacked XY Area Chart Demo 3", "X Value",
            "Y Value", tablexydataset, PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    DateAxis dateaxis = new DateAxis("Date");
    xyplot.setDomainAxis(dateaxis);//from   w  w w.  j a va  2 s .co m
    dateaxis.setLowerMargin(0.0D);
    dateaxis.setUpperMargin(0.0D);
    StackedXYAreaRenderer2 stackedxyarearenderer2 = (StackedXYAreaRenderer2) xyplot.getRenderer();
    stackedxyarearenderer2.setRoundXCoordinates(true);
    return jfreechart;
}

From source file:br.ufrgs.enq.jcosmo.ui.SigmaProfileAreaPanel.java

public SigmaProfileAreaPanel() {
    setLayout(new BorderLayout());

    sigmaProfileChart = ChartFactory.createStackedXYAreaChart(null, "sigma [e/]", "p(sigma)area []",
            dataset, PlotOrientation.VERTICAL, true, true, false);

    sigmaProfilePlot = sigmaProfileChart.getXYPlot();
    sigmaProfilePlot.getDomainAxis().setAutoRange(false);
    sigmaProfilePlot.getDomainAxis().setRange(new Range(-0.025, 0.025));
    sigmaProfilePlot.setBackgroundPaint(Color.WHITE);

    sigmaProfilePlot.setAxisOffset(new RectangleInsets(8, 0, 0, 16));
    sigmaProfilePlot.setDomainGridlinesVisible(false);
    sigmaProfilePlot.setRangeGridlinesVisible(false);

    Font font = new Font("DeJaVu Serif", Font.BOLD, 16);
    Font fontMini = new Font("DeJaVu Serif", 0, 12);

    sigmaProfileChart.getLegend().setItemFont(fontMini);
    sigmaProfilePlot.getDomainAxis().setLabelFont(font);
    sigmaProfilePlot.getRangeAxis().setLabelFont(font);
    sigmaProfilePlot.getDomainAxis().setTickLabelFont(fontMini);
    sigmaProfilePlot.getRangeAxis().setTickLabelFont(fontMini);

    sigmaProfilePlot.getDomainAxis().setAxisLinePaint(Color.BLACK);
    sigmaProfilePlot.getDomainAxis().setTickMarkPaint(Color.BLACK);
    sigmaProfilePlot.getDomainAxis().setTickMarkInsideLength(4);
    sigmaProfilePlot.getDomainAxis().setTickMarkOutsideLength(0);

    sigmaProfilePlot.getRangeAxis().setAxisLinePaint(Color.BLACK);
    sigmaProfilePlot.getRangeAxis().setTickMarkPaint(Color.BLACK);
    sigmaProfilePlot.getRangeAxis().setTickMarkInsideLength(4);
    sigmaProfilePlot.getRangeAxis().setTickMarkOutsideLength(0);

    add(new ChartPanel(sigmaProfileChart), BorderLayout.CENTER);
}

From source file:lisong_mechlab.view.graphs.DpsGraph.java

JFreeChart makechart() {
    JFreeChart chart = ChartFactory.createStackedXYAreaChart("Max DPS over range for " + loadout, "range [m]",
            "damage / second", getSeries(), PlotOrientation.VERTICAL, true, true, false);
    chart.getPlot().setDrawingSupplier(colours);

    chart.getLegend().setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.getLegend().setVerticalAlignment(VerticalAlignment.TOP);

    LegendTitle legendTitle = chart.getLegend();
    XYTitleAnnotation titleAnnotation = new XYTitleAnnotation(0.98, 0.98, legendTitle,
            RectangleAnchor.TOP_RIGHT);/*from  ww w .  ja  va  2s.c o m*/
    titleAnnotation.setMaxWidth(0.4);
    ((XYPlot) (chart.getPlot())).addAnnotation(titleAnnotation);
    chart.removeLegend();

    return chart;
}

From source file:lisong_mechlab.view.graphs.DamageGraph.java

JFreeChart makechart() {
    return ChartFactory.createStackedXYAreaChart("Max Sustained DPS over range for " + loadout, "range [m]",
            "damage / second", getSeries(), PlotOrientation.VERTICAL, true, true, false);
}

From source file:lisong_mechlab.view.graphs.SustainedDpsGraph.java

JFreeChart makechart() {
    JFreeChart chart = ChartFactory.createStackedXYAreaChart("Max Sustained DPS over range for " + loadout,
            "range [m]", "damage / second", getSeries(), PlotOrientation.VERTICAL, true, true, false);
    chart.getPlot().setDrawingSupplier(colours);

    chart.getLegend().setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.getLegend().setVerticalAlignment(VerticalAlignment.TOP);

    LegendTitle legendTitle = chart.getLegend();
    XYTitleAnnotation titleAnnotation = new XYTitleAnnotation(0.98, 0.98, legendTitle,
            RectangleAnchor.TOP_RIGHT);//from w w w .  j  a va  2s.  com
    titleAnnotation.setMaxWidth(0.4);
    ((XYPlot) (chart.getPlot())).addAnnotation(titleAnnotation);
    chart.removeLegend();

    return chart;
}