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

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

Introduction

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

Prototype

public TimeSeries(Comparable name, Class timePeriodClass) 

Source Link

Document

Creates a new (empty) time series with the specified name and class of RegularTimePeriod .

Usage

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

/**
 * Test program that will display a JFreeChart showing interpolated data points.
 * /*from w  w w. j av a 2  s. com*/
 * @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.
 * //from   w ww  .  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) {
    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:monitoring.suhu.DynamicCharts.java

public DynamicCharts(final String title) {
    super(title);
    this.series = new TimeSeries("Temperature", Millisecond.class);
    final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series);
    chart = createChart(dataset);/*from   w  ww.j  a va 2  s. c  om*/
    final ChartPanel chartPanel = new ChartPanel(chart);
    final JPanel content = new JPanel(new BorderLayout());
    content.add(chartPanel);
    chartPanel.setPreferredSize(new java.awt.Dimension(700, 500));
    setContentPane(content);
}

From source file:application.TrendPlot.java

/**
 * Konstruktren kaller initialize()/*from   w  ww. j  a  v  a2s . co m*/
 *
 * @param plotName
 * 
 */
public TrendPlot(String data, String plotName) {

    this.plotName = plotName;
    timeSeries = new TimeSeries(data, Millisecond.class);

    initialize();
}

From source file:org.gaixie.micrite.car.action.CarfileChartAction.java

/**
 * ?//w  w w  .  j a  v a2 s .  c  om
 * @return
 */
private static XYDataset createDataset() {
    TimeSeries timeseries = new TimeSeries("??", org.jfree.data.time.Minute.class);
    Hour hour = new Hour();
    timeseries.add(new Minute(1, hour), 10.199999999999999D);
    timeseries.add(new Minute(3, hour), 17.300000000000001D);
    timeseries.add(new Minute(9, hour), 14.6D);
    timeseries.add(new Minute(11, hour), 11.9D);
    timeseries.add(new Minute(15, hour), 13.5D);
    timeseries.add(new Minute(19, hour), 10.9D);
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries);
    return timeseriescollection;
}

From source file:org.gaixie.micrite.crm.action.CustomerChartAction.java

/**
 * ?/*from   ww w .  j  a  v a  2s. com*/
 * @return
 */
private static XYDataset createDataset() {
    TimeSeries timeseries = new TimeSeries("Per Minute Data", org.jfree.data.time.Minute.class);
    Hour hour = new Hour();
    timeseries.add(new Minute(1, hour), 10.199999999999999D);
    timeseries.add(new Minute(3, hour), 17.300000000000001D);
    timeseries.add(new Minute(9, hour), 14.6D);
    timeseries.add(new Minute(11, hour), 11.9D);
    timeseries.add(new Minute(15, hour), 13.5D);
    timeseries.add(new Minute(19, hour), 10.9D);
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries);
    return timeseriescollection;
}

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

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title.//from   w  w  w .j a va2s.com
 */
public Graph(final String title) {

    super(title);
    this.series = new TimeSeries("Random Data", Millisecond.class);
    final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series);
    final JFreeChart chart = createChart(dataset);

    final ChartPanel chartPanel = new ChartPanel(chart);
    final JButton button = new JButton("Add New Data Item");
    button.setActionCommand("ADD_DATA");
    button.addActionListener(this);

    final JPanel content = new JPanel(new BorderLayout());
    content.add(chartPanel);
    // content.add(button, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(content);

}

From source file:networkanalyzer.DynamicPing.java

public DynamicPing() {
    this.series = new TimeSeries("Ping", Second.class);

    final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series);
    chart = createChart(dataset);//from w  w  w .  jav a 2  s .c o  m

    //background color chart
    chart.setBackgroundPaint(Color.WHITE);

    chartPanel = new ChartPanel(chart);
    chartPanel.setSize(504, 346);

}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.PmdTimeChartStrategy.java

public void fillDataset() {
    TimeSeries s1 = new TimeSeries(this.bundle.getString("report.pmd.label.nbclasses"), this.periodClass);
    TimeSeries s2 = new TimeSeries(this.bundle.getString("report.pmd.label.nbviolations"), this.periodClass);
    Iterator iter = mResults.iterator();
    while (iter.hasNext()) {

        PmdReportBean pmd = (PmdReportBean) iter.next();
        Date date = pmd.getDateGeneration();
        s1.addOrUpdate(getChartDate(this.timePeriod.normalize(date)), pmd.getNbClasses());
        s2.addOrUpdate(getChartDate(this.timePeriod.normalize(date)), pmd.getNbViolations());
    }/*  w w  w  .  j a  v a  2  s  . c om*/

    defaultdataset.addSeries(s1);
    defaultdataset.addSeries(s2);

}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.CpdTimeChartStrategy.java

public void fillDataset() {
    TimeSeries s1 = new TimeSeries(this.bundle.getString("report.cpd.label.nbclasses"), this.periodClass);
    TimeSeries s2 = new TimeSeries(this.bundle.getString("report.cpd.label.nbduplicate"), this.periodClass);
    Iterator iter = mResults.iterator();
    while (iter.hasNext()) {

        CpdReportBean cpd = (CpdReportBean) iter.next();
        Date date = cpd.getDateGeneration();
        s1.addOrUpdate(getChartDate(this.timePeriod.normalize(date)), cpd.getNbClasses());
        s2.addOrUpdate(getChartDate(this.timePeriod.normalize(date)), cpd.getNbDuplicate());
        // s3.addOrUpdate( day, cober.getNbClasses() );
    }/*from www.  j av a2  s .co  m*/

    defaultdataset.addSeries(s1);
    defaultdataset.addSeries(s2);

}