Example usage for org.jfree.data.time TimeSeries add

List of usage examples for org.jfree.data.time TimeSeries add

Introduction

In this page you can find the example usage for org.jfree.data.time TimeSeries add.

Prototype

public void add(RegularTimePeriod period, Number value) 

Source Link

Document

Adds a new data item to the series and sends a org.jfree.data.general.SeriesChangeEvent to all registered listeners.

Usage

From source file:de.codesourcery.eve.skills.ui.ChartTest.java

public static void main(String[] args) {

    TimeSeries s1 = new TimeSeries("L&G European Index Trust");
    s1.add(new Day(1, 2, 2001), 181.8);
    s1.add(new Month(3, 2001), 167.3);
    s1.add(new Month(4, 2001), 153.8);
    s1.add(new Month(5, 2001), 167.6);
    s1.add(new Month(6, 2001), 158.8);
    s1.add(new Month(7, 2001), 148.3);
    s1.add(new Month(8, 2001), 153.9);
    s1.add(new Month(9, 2001), 142.7);
    s1.add(new Month(10, 2001), 123.2);
    s1.add(new Month(11, 2001), 131.8);
    s1.add(new Month(12, 2001), 139.6);
    s1.add(new Month(1, 2002), 142.9);
    s1.add(new Month(2, 2002), 138.7);
    s1.add(new Month(3, 2002), 137.3);
    s1.add(new Month(4, 2002), 143.9);
    s1.add(new Month(5, 2002), 139.8);
    s1.add(new Month(6, 2002), 137.0);
    s1.add(new Month(7, 2002), 132.8);
    TimeSeries s2 = new TimeSeries("L&G UK Index Trust");
    s2.add(new Month(2, 2001), 129.6);
    s2.add(new Month(3, 2001), 123.2);
    s2.add(new Month(4, 2001), 117.2);
    s2.add(new Month(5, 2001), 124.1);
    s2.add(new Month(6, 2001), 122.6);
    s2.add(new Month(7, 2001), 119.2);
    s2.add(new Month(8, 2001), 116.5);
    s2.add(new Month(9, 2001), 112.7);
    s2.add(new Month(10, 2001), 101.5);
    s2.add(new Month(11, 2001), 106.1);
    s2.add(new Month(12, 2001), 110.3);
    s2.add(new Month(1, 2002), 111.7);
    s2.add(new Month(2, 2002), 111.0);
    s2.add(new Month(3, 2002), 109.6);
    s2.add(new Month(4, 2002), 113.2);
    s2.add(new Month(5, 2002), 111.6);
    s2.add(new Month(6, 2002), 108.8);
    s2.add(new Month(7, 2002), 101.6);

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);//  w ww  .  j av a 2 s .c o m
    dataset.addSeries(s2);

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    // display chart
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setMouseZoomable(true, false);

    JFrame frame = new JFrame("test");
    frame.setContentPane(chartPanel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

}

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

/**
 * Test program that will display a JFreeChart showing interpolated data points.
 * /*from w  w  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:com.bpd.jfreechart.Chart.java

/**
 * Test program that will display a JFreeChart showing interpolated data points.
 * /* w w  w. j a  v  a  2s.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) {
    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;
    }

    List<Point<Number, Number>> list1 = new ArrayList<Point<Number, Number>>();
    list1.add(new Point<Number, Number>(100, 100));
    list1.add(new Point<Number, Number>(200, 200));
    list1.add(new Point<Number, Number>(300, 400));
    list1.add(new Point<Number, Number>(400, 200));
    list1.add(new Point<Number, Number>(500, 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));

    List<List<Point<Number, Number>>> lists = new ArrayList<List<Point<Number, Number>>>();
    List<Point<Number, Number>> extrapolatedList1 = new ArrayList<Point<Number, Number>>();
    List<Point<Number, Number>> extrapolatedList2 = new ArrayList<Point<Number, Number>>();
    if ("1".equals(option)) {
        lists.add(list1);
        extrapolatedList1 = Interpolator.interpolate(list1, lists);
    } else if ("2".equals(option)) {
        lists.add(list2);
        extrapolatedList2 = Interpolator.interpolate(list2, lists);
    } else if ("0".equals(option)) {
        lists.add(list1);
        lists.add(list2);
        extrapolatedList1 = Interpolator.interpolate(list1, lists);
        extrapolatedList2 = Interpolator.interpolate(list2, lists);
    }

    TimeSeries series1 = new TimeSeries("Series 1", FixedMillisecond.class);
    for (Point<Number, Number> dataPoint : extrapolatedList1) {
        if ("1".equals(option) || "0".equals(option)) {
            series1.add(new FixedMillisecond(dataPoint.getX().longValue()), dataPoint.getY());
        }
        System.err.println(dataPoint.getX() + "\t" + dataPoint.getY());
    }

    System.err.println();

    TimeSeries series2 = new TimeSeries("Series 2", FixedMillisecond.class);
    for (Point<Number, Number> dataPoint : extrapolatedList2) {
        if ("2".equals(option) || "0".equals(option)) {
            series2.add(new FixedMillisecond(dataPoint.getX().longValue()), dataPoint.getY());
        }
        System.err.println(dataPoint.getX() + "\t" + dataPoint.getY());
    }

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

    JFreeChart chart = ChartFactory.createXYLineChart("Test", null, null, dataset, PlotOrientation.VERTICAL,
            false, true, false);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesShapesVisible(1, true);

    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.TimeSeriesDemo14.java

private static XYDataset createDataset() {
    TimeSeries timeseries = new TimeSeries("Bugs");
    timeseries.add(new Day(27, 6, 2005), 478474D);
    timeseries.add(new Day(24, 1, 2006), 633804D);
    timeseries.add(new Day(28, 4, 2006), 694096D);
    timeseries.add(new Day(12, 5, 2006), 704680D);
    timeseries.add(new Day(16, 5, 2006), 709599D);
    timeseries.add(new Day(21, 6, 2006), 734754D);
    timeseries.add(new Day(27, 7, 2006), 760008D);
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    timeseriescollection.addSeries(timeseries);
    return timeseriescollection;
}

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

private static IntervalXYDataset createDataset() {
    TimeSeries timeseries = new TimeSeries("Completion");
    timeseries.add(new Day(19, 1, 2007), 3343000D);
    timeseries.add(new Day(20, 1, 2007), 3420000D);
    timeseries.add(new Day(21, 1, 2007), 3515000D);
    timeseries.add(new Day(22, 1, 2007), 3315000D);
    timeseries.add(new Day(23, 1, 2007), 3490000D);
    timeseries.add(new Day(24, 1, 2007), 3556000D);
    timeseries.add(new Day(25, 1, 2007), 3383000D);
    timeseries.add(new Day(26, 1, 2007), 3575000D);
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    timeseriescollection.addSeries(timeseries);
    return timeseriescollection;
}

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

private static XYDataset createDataset() {
    TimeSeries timeseries = new TimeSeries("Heart Rate");
    timeseries.add(new Second(45, 6, 9, 1, 10, 2006), 143D);
    timeseries.add(new Second(33, 8, 9, 1, 10, 2006), 167D);
    timeseries.add(new Second(10, 10, 9, 1, 10, 2006), 189D);
    timeseries.add(new Second(19, 12, 9, 1, 10, 2006), 156D);
    timeseries.add(new Second(5, 15, 9, 1, 10, 2006), 176D);
    timeseries.add(new Second(12, 16, 9, 1, 10, 2006), 183D);
    timeseries.add(new Second(6, 18, 9, 1, 10, 2006), 138D);
    timeseries.add(new Second(11, 20, 9, 1, 10, 2006), 102D);
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    timeseriescollection.addSeries(timeseries);
    return timeseriescollection;
}

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

private static IntervalXYDataset createDataset() {
    TimeSeries timeseries = new TimeSeries("Temperature");
    timeseries.add(new Day(1, 4, 2006), 14.5D);
    timeseries.add(new Day(2, 4, 2006), 11.5D);
    timeseries.add(new Day(3, 4, 2006), 13.699999999999999D);
    timeseries.add(new Day(4, 4, 2006), 10.5D);
    timeseries.add(new Day(5, 4, 2006), 14.9D);
    timeseries.add(new Day(6, 4, 2006), 15.699999999999999D);
    timeseries.add(new Day(7, 4, 2006), 11.5D);
    timeseries.add(new Day(8, 4, 2006), 9.5D);
    timeseries.add(new Day(9, 4, 2006), 10.9D);
    timeseries.add(new Day(10, 4, 2006), 14.1D);
    timeseries.add(new Day(11, 4, 2006), 12.300000000000001D);
    timeseries.add(new Day(12, 4, 2006), 14.300000000000001D);
    timeseries.add(new Day(13, 4, 2006), 19D);
    timeseries.add(new Day(14, 4, 2006), 17.899999999999999D);
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    timeseriescollection.addSeries(timeseries);
    return timeseriescollection;
}

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

private static IntervalXYDataset createDataset1() {
    TimeSeries timeseries = new TimeSeries("Series 1");
    timeseries.add(new Day(1, 3, 2002), 12353.299999999999D);
    timeseries.add(new Day(2, 3, 2002), 13734.4D);
    timeseries.add(new Day(3, 3, 2002), 14525.299999999999D);
    timeseries.add(new Day(4, 3, 2002), 13984.299999999999D);
    timeseries.add(new Day(5, 3, 2002), 12999.4D);
    timeseries.add(new Day(6, 3, 2002), 14274.299999999999D);
    timeseries.add(new Day(7, 3, 2002), 15943.5D);
    timeseries.add(new Day(8, 3, 2002), 14845.299999999999D);
    timeseries.add(new Day(9, 3, 2002), 14645.4D);
    timeseries.add(new Day(10, 3, 2002), 16234.6D);
    timeseries.add(new Day(11, 3, 2002), 17232.299999999999D);
    timeseries.add(new Day(12, 3, 2002), 14232.200000000001D);
    timeseries.add(new Day(13, 3, 2002), 13102.200000000001D);
    timeseries.add(new Day(14, 3, 2002), 14230.200000000001D);
    timeseries.add(new Day(15, 3, 2002), 11235.200000000001D);
    return new TimeSeriesCollection(timeseries);
}

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

private static XYDataset createDataset2() {
    TimeSeries timeseries = new TimeSeries("Series 2");
    timeseries.add(new Day(3, 3, 2002), 16853.200000000001D);
    timeseries.add(new Day(4, 3, 2002), 19642.299999999999D);
    timeseries.add(new Day(5, 3, 2002), 18253.5D);
    timeseries.add(new Day(6, 3, 2002), 15352.299999999999D);
    timeseries.add(new Day(7, 3, 2002), 13532D);
    timeseries.add(new Day(8, 3, 2002), 12635.299999999999D);
    timeseries.add(new Day(9, 3, 2002), 13998.200000000001D);
    timeseries.add(new Day(10, 3, 2002), 11943.200000000001D);
    timeseries.add(new Day(11, 3, 2002), 16943.900000000001D);
    timeseries.add(new Day(12, 3, 2002), 17843.200000000001D);
    timeseries.add(new Day(13, 3, 2002), 16495.299999999999D);
    timeseries.add(new Day(14, 3, 2002), 17943.599999999999D);
    timeseries.add(new Day(15, 3, 2002), 18500.700000000001D);
    timeseries.add(new Day(16, 3, 2002), 19595.900000000001D);
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries);
    return timeseriescollection;
}

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

public static XYDataset createDataset() {
    TimeSeries timeseries = new TimeSeries("L&G European Index Trust");
    timeseries.add(new Month(2, 2001), 181.80000000000001D);
    timeseries.add(new Month(3, 2001), 167.30000000000001D);
    timeseries.add(new Month(4, 2001), 153.80000000000001D);
    timeseries.add(new Month(5, 2001), 167.59999999999999D);
    timeseries.add(new Month(6, 2001), 158.80000000000001D);
    timeseries.add(new Month(7, 2001), 148.30000000000001D);
    timeseries.add(new Month(8, 2001), 153.90000000000001D);
    timeseries.add(new Month(9, 2001), 142.69999999999999D);
    timeseries.add(new Month(10, 2001), 123.2D);
    timeseries.add(new Month(11, 2001), 131.80000000000001D);
    timeseries.add(new Month(12, 2001), 139.59999999999999D);
    timeseries.add(new Month(1, 2002), 142.90000000000001D);
    timeseries.add(new Month(2, 2002), 138.69999999999999D);
    timeseries.add(new Month(3, 2002), 137.30000000000001D);
    timeseries.add(new Month(4, 2002), 143.90000000000001D);
    timeseries.add(new Month(5, 2002), 139.80000000000001D);
    timeseries.add(new Month(6, 2002), 137D);
    timeseries.add(new Month(7, 2002), 132.80000000000001D);
    TimeSeries timeseries1 = MovingAverage.createMovingAverage(timeseries, "Six Month Moving Average", 6, 0);
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    timeseriescollection.addSeries(timeseries);
    timeseriescollection.addSeries(timeseries1);
    return timeseriescollection;
}