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:org.jfree.chart.demo.SerializationTest1.java

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title.//w  ww. j  ava 2  s  .  co  m
 */
public SerializationTest1(final String title) {

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

    // SERIALIZE - DESERIALIZE for testing purposes
    JFreeChart deserializedChart = null;

    try {
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        final ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(chart);
        out.close();
        chart = null;
        dataset = null;
        this.series = null;
        System.gc();

        final ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        deserializedChart = (JFreeChart) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    final TimeSeriesCollection c = (TimeSeriesCollection) deserializedChart.getXYPlot().getDataset();
    this.series = c.getSeries(0);
    // FINISHED TEST

    final ChartPanel chartPanel = new ChartPanel(deserializedChart);
    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:com.hello2morrow.sonargraph.jenkinsplugin.model.TimeSeriesPlot.java

/**
 * Creates a XYDataset from a CSV file./*from  w  w  w. j  av a2s.  c  o m*/
 */
@Override
protected XYDataset createXYDataset(SonargraphMetrics metric, int maximumNumberOfDataPoints)
        throws IOException {
    assert metric != null : "Parameter 'metric' of method 'createXYDataset' must not be null";

    //For some reason, the class of the time series is required here, otherwise an exception is thrown that a Date instance is expected.
    @SuppressWarnings("deprecation")
    TimeSeries timeSeries = new TimeSeries(metric.getShortDescription(), FixedMillisecond.class);

    List<IDataPoint> dataset = m_datasetProvider.readMetricValues(metric);
    int size = dataset.size();
    SonargraphLogger.INSTANCE.fine(size + " data points found for metric '" + metric.getStandardName()
            + "' in file '" + m_datasetProvider.getStorageName() + "'");
    List<IDataPoint> reducedSet = reduceDataSet(dataset, maximumNumberOfDataPoints);

    BuildDataPoint point = null;
    for (IDataPoint datapoint : reducedSet) {
        if (datapoint instanceof InvalidDataPoint) {
            // We could create a gap in the graph by adding null:
            // xySeries.add(datapoint.getX(), null);
            continue;
        } else if (datapoint instanceof BuildDataPoint) {
            point = (BuildDataPoint) datapoint;
            if (point.getTimestamp() == 0) {
                continue;
            }

            timeSeries.add(new FixedMillisecond(point.getTimestamp()), point.getY());
        }
    }
    if (point != null) {
        setTimestampOfLastDisplayedPoint(point.getTimestamp());
    }

    TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();
    TimeSeries avgDataset = MovingAverage.createMovingAverage(timeSeries,
            "Avg of " + metric.getShortDescription(), MOVING_AVG_PERIOD, 0);
    setDataSetSize(avgDataset.getItemCount());
    timeSeriesCollection.addSeries(avgDataset);

    //SG-325: We cannot use JFreeChart methods of version 1.0.14
    //        setMinimumValue(avgDataset.getMinY());
    //        setMaximumValue(avgDataset.getMaxY());

    // We only show the average data and omit the original data
    //        timeSeriesCollection.addSeries(timeSeries);
    for (Object item : avgDataset.getItems()) {
        if (item instanceof TimeSeriesDataItem) {
            checkMinMaxYValue(((TimeSeriesDataItem) item).getValue().doubleValue());
        }
    }
    return timeSeriesCollection;
}

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

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title./*ww  w. j av  a  2s . c  o m*/
 */
public DynamicDataDemo2(final String title) {

    super(title);
    this.series1 = new TimeSeries("Random 1", Millisecond.class);
    this.series2 = new TimeSeries("Random 2", Millisecond.class);
    final TimeSeriesCollection dataset1 = new TimeSeriesCollection(this.series1);
    final TimeSeriesCollection dataset2 = new TimeSeriesCollection(this.series2);
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Dynamic Data Demo 2", "Time", "Value",
            dataset1, true, true, false);
    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //      plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds

    plot.setDataset(1, dataset2);
    final NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2");
    rangeAxis2.setAutoRangeIncludesZero(false);
    plot.setRenderer(1, new DefaultXYItemRenderer());
    plot.setRangeAxis(1, rangeAxis2);
    plot.mapDatasetToRangeAxis(1, 1);

    final JPanel content = new JPanel(new BorderLayout());

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    final JButton button1 = new JButton("Add To Series 1");
    button1.setActionCommand("ADD_DATA_1");
    button1.addActionListener(this);

    final JButton button2 = new JButton("Add To Series 2");
    button2.setActionCommand("ADD_DATA_2");
    button2.addActionListener(this);

    final JButton button3 = new JButton("Add To Both");
    button3.setActionCommand("ADD_BOTH");
    button3.addActionListener(this);

    final JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(button1);
    buttonPanel.add(button2);
    buttonPanel.add(button3);

    content.add(buttonPanel, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(content);

}

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

/**
 *
 *///  w w  w.j a  v  a  2s.c om
public void createChart() {

    XYPlot xyplot = (XYPlot) report.getPlot();
    if (this.decoratedChart instanceof TimeChartRenderer && this.results != null && !this.results.isEmpty()) {

        Iterator iter = this.results.iterator();
        TimeSeriesCollection defaultdataset = new TimeSeriesCollection();
        TimeSeries s1 = new TimeSeries("% success", Day.class);

        while (iter.hasNext()) {
            SurefireReportBean surefire = (SurefireReportBean) iter.next();
            Date date = surefire.getDateGeneration();
            s1.addOrUpdate(new Day(TimePeriod.DAY.normalize(date)), surefire.getSucessRate() / PCENT);

        }

        defaultdataset.addSeries(s1);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setSeriesPaint(0, ChartColor.DARK_BLUE);
        renderer.setBaseShapesVisible(true);
        renderer.setDrawOutlines(true);
        StandardXYItemLabelGenerator labelgenerator = new StandardXYItemLabelGenerator(
                StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, TimePeriod.DAY.getDateFormat(),
                NumberFormat.getPercentInstance(Locale.getDefault()));
        renderer.setBaseItemLabelGenerator(labelgenerator);
        renderer.setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, ITEM_LABEL_FONT_SIZE));
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BASELINE_RIGHT));

        renderer.setBaseStroke(new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

        LegendTitle legendtitle = new LegendTitle(xyplot.getRenderer(0));
        legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle.setFrame(new BlockBorder());
        legendtitle.setBackgroundPaint(ChartColor.WHITE);

        LegendTitle legendtitle1 = new LegendTitle(renderer);
        legendtitle1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle1.setFrame(new BlockBorder());
        legendtitle1.setBackgroundPaint(ChartColor.WHITE);

        BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
        blockcontainer.add(legendtitle, RectangleEdge.LEFT);
        blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
        blockcontainer.add(new EmptyBlock(BLOCK_CONTAINER_WIDTH, 0.0D));

        CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
        compositetitle.setPosition(RectangleEdge.BOTTOM);

        report.clearSubtitles();
        report.addSubtitle(compositetitle);

        xyplot.setDataset(1, defaultdataset);

        NumberAxis valueaxis = new NumberAxis("% success");
        valueaxis.setLowerMargin(0.0D);
        valueaxis.setUpperMargin(AXIS_UPPER_MARGIN);
        valueaxis.setRangeWithMargins(0.0D, 1.0D);
        valueaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
        xyplot.setRangeAxis(1, valueaxis);
        xyplot.mapDatasetToRangeAxis(1, 1);
        xyplot.setRenderer(1, renderer);
    }

}

From source file:org.activequant.util.charting.Chart.java

/**
 * method to add a line series chart to the current chart. 
 * @param title//from w  w w  .j a  v a2  s .com
 * @param dateAndValues
 */
public void addLineSeriesChart(String title, List<Tuple<TimeStamp, Double>> dateAndValues) {

    // creating a new jfree chart time series object. 
    final TimeSeries ts = new TimeSeries(title, Millisecond.class);

    // iterate over the incoming value tuples and add them.  
    for (Tuple<TimeStamp, Double> tuple : dateAndValues) {
        TimeSeriesDataItem item = new TimeSeriesDataItem(new Millisecond(tuple.getObject1().getDate()),
                tuple.getObject2());
        ts.addOrUpdate(item.getPeriod(), item.getValue());
    }

    datasets.add(ts);

    // 
    final TimeSeriesCollection dataset = new TimeSeriesCollection(ts);

    // add it to the chart plot. 
    final XYPlot plot1 = chart.getXYPlot();

    // disable all shape rendering. 
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setDrawOutlines(false);
    renderer.setUseOutlinePaint(false);
    renderer.setShapesVisible(false);
    // finally add the data set to chart 
    plot1.setDataset(datasets.size(), dataset);
    plot1.setRenderer(datasets.size(), renderer);
}

From source file:view.PrograssCharts.java

/**
 * Creates new form PrograssCharts// w w  w  .j  a va  2  s . c  o  m
 */
public PrograssCharts(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    try {
        initComponents();
        setSize(1400, 800);
        jPanel1.setVisible(false);
        jPanel2.setVisible(false);

        new Thread(new Runnable() {

            @Override
            public void run() {
                loading1();
                loading2();
                run();

            }
        }).start();

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
        dataset.setValue(QuestionLab.cat1, "gfdg", "Collectns");
        dataset.setValue(QuestionLab.cat2, "gfdg", "Data");
        dataset.setValue(QuestionLab.cat3, "gfdg", "Dev");
        dataset.setValue(QuestionLab.cat4, "gfdg", "Excep");
        dataset.setValue(QuestionLab.cat5, "gfdg", "File");
        dataset.setValue(QuestionLab.cat6, "gfdg", "FlowCon");
        dataset.setValue(QuestionLab.cat7, "gfdg", "Format");
        dataset.setValue(QuestionLab.cat8, "gfdg", "GC");
        dataset.setValue(QuestionLab.cat9, "gfdg", "IC");
        dataset.setValue(QuestionLab.cat10, "gfdg", "VarArgs");
        dataset.setValue(QuestionLab.cat11, "gfdg", "Fundamt");
        dataset.setValue(QuestionLab.cat12, "gfdg", "Modif");
        dataset.setValue(QuestionLab.cat13, "gfdg", "OOP");
        dataset.setValue(QuestionLab.cat14, "gfdg", "Vari");
        dataset.setValue(QuestionLab.cat15, "gfdg", "String");
        dataset.setValue(QuestionLab.cat16, "gfdg", "Threads");
        dataset.setValue(QuestionLab.cat17, "gfdg", "WC");
        JFreeChart freeChart = ChartFactory.createBarChart("Exam Prograss by Subjects", "Subject", "Marks",
                dataset, PlotOrientation.VERTICAL, false, true, false);
        //JFreeChart freeChart1 = ChartFactory.createBarChart("Income", " Name", "Incomesss", dataset1, PlotOrientation.VERTICAL, false, true, false);
        TimeSeries pop = new TimeSeries("Population", Day.class);

        //JFreeChart chart=ChartFactory.create
        CategoryPlot plot = freeChart.getCategoryPlot();
        plot.setRangeGridlinePaint(Color.BLUE);
        ChartFrame frame = new ChartFrame("Exam Prograss", freeChart);

        //        frame.setVisible(true);
        //        frame.setSize(550, 450);
        // JPanel jPanel1 = new JPanel();
        jPanel1.setLayout(new java.awt.BorderLayout());

        ChartPanel CP = new ChartPanel(freeChart);
        CP.setPreferredSize(new Dimension(785, 440));
        CP.setMouseWheelEnabled(true);

        jPanel1.add(CP);
        jPanel1.revalidate();

        ArrayList<Exam> setChartValue = ServerConnector.getServerConnector().getExamController()
                .getPreviousMarks(PracticeExamLogIn.studentNic);
        for (Exam exam : setChartValue) {
            //dataset1.setValue(exam.getMarks(), "gfdg9", exam.getDate());
            pop.addOrUpdate(new Day(exam.getDate()), exam.getMarks());
            System.out.println("mar" + exam.getMarks());
            System.out.println("date" + exam.getDate());
        }
        TimeSeriesCollection myDataset = new TimeSeriesCollection();
        myDataset.addSeries(pop);
        JFreeChart myChart = ChartFactory.createTimeSeriesChart("Population Your Marks", "Date", "Population",
                myDataset, true, true, false);
        //try {
        //ChartUtilities.saveChartAsJPEG(new File("C:\\chart.jpg"), chart, 500, 300);
        //} catch (IOException e) {
        //System.err.println("Problem occurred creating chart.");
        //}

        //JFreeChart chart=ChartFactory.create
        CategoryPlot plot1 = freeChart.getCategoryPlot();
        plot1.setRangeGridlinePaint(Color.BLUE);
        //ChartFrame frame1 = new ChartFrame("Exam Prograss", freeChart1);

        //        frame.setVisible(true);
        //        frame.setSize(550, 450);
        // JPanel jPanel1 = new JPanel();
        jPanel2.setLayout(new java.awt.BorderLayout());

        ChartPanel CP1 = new ChartPanel(myChart);
        CP1.setPreferredSize(new Dimension(785, 440));
        CP1.setMouseWheelEnabled(true);

        jPanel2.add(CP1);
        jPanel2.revalidate();

    } catch (RemoteException | ClassNotFoundException | SQLException | NotBoundException
            | MalformedURLException ex) {
        Logger.getLogger(PrograssCharts.class.getName()).log(Level.SEVERE, null, ex);
    }

}

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

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title./*from w  w  w. j av a2  s.c o m*/
 */
public DynamicDataDemo3(final String title) {

    super(title);

    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.datasets = new TimeSeriesCollection[SUBPLOT_COUNT];

    for (int i = 0; i < SUBPLOT_COUNT; i++) {
        this.lastValue[i] = 100.0;
        final TimeSeries series = new TimeSeries("Random " + i, Millisecond.class);
        this.datasets[i] = new TimeSeriesCollection(series);
        final NumberAxis rangeAxis = new NumberAxis("Y" + i);
        rangeAxis.setAutoRangeIncludesZero(false);
        final XYPlot subplot = new XYPlot(this.datasets[i], null, rangeAxis, new StandardXYItemRenderer());
        subplot.setBackgroundPaint(Color.lightGray);
        subplot.setDomainGridlinePaint(Color.white);
        subplot.setRangeGridlinePaint(Color.white);
        plot.add(subplot);
    }

    final JFreeChart chart = new JFreeChart("Dynamic Data Demo 3", plot);
    //        chart.getLegend().setAnchor(Legend.EAST);
    chart.setBorderPaint(Color.black);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //      plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds

    final JPanel content = new JPanel(new BorderLayout());

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    final JPanel buttonPanel = new JPanel(new FlowLayout());

    for (int i = 0; i < SUBPLOT_COUNT; i++) {
        final JButton button = new JButton("Series " + i);
        button.setActionCommand("ADD_DATA_" + i);
        button.addActionListener(this);
        buttonPanel.add(button);
    }
    final JButton buttonAll = new JButton("ALL");
    buttonAll.setActionCommand("ADD_ALL");
    buttonAll.addActionListener(this);
    buttonPanel.add(buttonAll);

    content.add(buttonPanel, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 470));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(content);

}

From source file:LoggerGUI.DataLogger.java

public DataLogger(String title) {
    super(title);
    initialize();//from w w w  . j a v  a2 s. c om

    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.datasets = new TimeSeriesCollection[INPUT_COUNT];

    this.lastValue[0] = 100.0;
    this.lastValue[1] = 100.0;
    this.lastValue[2] = 100.0;
    this.lastValue[3] = 100.0;
       
        
        
       
        
    final TimeSeries s0 = new TimeSeries("A0", Millisecond.class);
    final TimeSeries s1 = new TimeSeries("A1", Millisecond.class);
    final TimeSeries s2 = new TimeSeries("A2", Millisecond.class);
    final TimeSeries s3 = new TimeSeries("A3", Millisecond.class);
        
        
        
    this.datasets[0] = new TimeSeriesCollection(s0);
    this.datasets[1] = new TimeSeriesCollection(s1);
    this.datasets[2] = new TimeSeriesCollection(s2);
    this.datasets[3] = new TimeSeriesCollection(s3);
       
        

    final NumberAxis rangeAxis = new NumberAxis("ADC Signal");

    rangeAxis.setAutoRangeIncludesZero(false);
    XYPlot subplot;

        
    XYLineAndShapeRenderer renderer =  new XYLineAndShapeRenderer(true,false);
    XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(true,false);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true,false);
    XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer(true,false);
        
    subplot= new XYPlot(
            new TimeSeriesCollection(), null, rangeAxis, new XYLineAndShapeRenderer(true,false)
    );
       
    plot.add(subplot);
       
        
        
    renderer.setBaseShapesVisible(false);
    renderer.setSeriesPaint(0, Color.red);
    subplot.setDataset(0,datasets[0]);
    subplot.setRenderer(0,renderer);
        
        
    renderer1.setBaseShapesVisible(false);
    renderer1.setSeriesPaint(0, Color.blue);
    subplot.setDataset(1,datasets[1]);
    subplot.setRenderer(1,renderer1);
        
        
    renderer2.setBaseShapesVisible(false);
    renderer2.setSeriesPaint(0, Color.black);
    subplot.setDataset(2,datasets[2]);
    subplot.setRenderer(2,renderer2);
        
    subplot.getRendererForDataset(subplot.getDataset(0)).setSeriesPaint(0, Color.red); 
    subplot.getRendererForDataset(subplot.getDataset(1)).setSeriesPaint(1, Color.blue);
    subplot.getRendererForDataset(subplot.getDataset(2)).setSeriesPaint(2, Color.black);
        
    renderer3.setBaseShapesVisible(false);
    renderer3.setSeriesPaint(0, Color.green);
    subplot.setDataset(3,datasets[3]);
    subplot.setRenderer(3,renderer3);
        
        
        
    final JFreeChart chart = new JFreeChart("Data Logger", plot);
    chart.setBorderPaint(Color.black);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);
        
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(20000.0);  // 60 seconds

    
    final JPanel content = new JPanel(new BorderLayout());

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    final JPanel buttonPanel = new JPanel(new FlowLayout());
        
    content.add(buttonPanel, BorderLayout.NORTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(600, 600));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(content);
        
        
}

From source file:com.continuent.bristlecone.evaluator.MovingAverageDemo.java

/**
 * Creates a dataset, one series containing unit trust prices, the other a
 * moving average.// ww  w .ja  v a  2 s  .  c o m
 *
 * @return The dataset.
 */
public XYDataset createDataset() {

    ArrayList<Double> s1 = new ArrayList<Double>();

    s1.add(181.8);
    s1.add(167.3);
    s1.add(153.8);
    s1.add(167.6);
    s1.add(158.8);
    s1.add(148.3);
    s1.add(153.9);
    s1.add(142.7);
    s1.add(123.2);
    s1.add(131.8);
    s1.add(139.6);
    s1.add(142.9);
    s1.add(138.7);
    s1.add(137.3);
    s1.add(143.9);
    s1.add(139.8);
    s1.add(137.0);
    s1.add(132.8);

    TimeSeries series1 = new TimeSeries("L&G European Index Trust", Millisecond.class);
    try {
        for (Double val : s1) {
            Thread.sleep(10);
            series1.add(new Millisecond(), val);
        }
    } catch (InterruptedException i) {
        //
    }

    TimeSeries s2 = MovingAverage.createMovingAverage(series1, "Six Month Moving Average", 100, 0);

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series1);
    dataset.addSeries(s2);

    return dataset;

}

From source file:com.android.ddmuilib.log.event.DisplaySync.java

/**
 * Resets the display.//w w w.j ava  2s.  c o  m
 */
@Override
void resetUI() {
    super.resetUI();
    XYPlot xyPlot = mChart.getXYPlot();

    XYBarRenderer br = new XYBarRenderer();
    mDatasetsSync = new TimePeriodValues[NUM_AUTHS];

    @SuppressWarnings("unchecked")
    List<String> mTooltipsSyncTmp[] = new List[NUM_AUTHS];
    mTooltipsSync = mTooltipsSyncTmp;

    mTooltipGenerators = new CustomXYToolTipGenerator[NUM_AUTHS];

    TimePeriodValuesCollection tpvc = new TimePeriodValuesCollection();
    xyPlot.setDataset(tpvc);
    xyPlot.setRenderer(0, br);

    XYLineAndShapeRenderer ls = new XYLineAndShapeRenderer();
    ls.setBaseLinesVisible(false);
    mDatasetsSyncTickle = new TimeSeries[NUM_AUTHS];
    TimeSeriesCollection tsc = new TimeSeriesCollection();
    xyPlot.setDataset(1, tsc);
    xyPlot.setRenderer(1, ls);

    mDatasetError = new TimeSeries("Errors", FixedMillisecond.class);
    xyPlot.setDataset(2, new TimeSeriesCollection(mDatasetError));
    XYLineAndShapeRenderer errls = new XYLineAndShapeRenderer();
    errls.setBaseLinesVisible(false);
    errls.setSeriesPaint(0, Color.RED);
    xyPlot.setRenderer(2, errls);

    for (int i = 0; i < NUM_AUTHS; i++) {
        br.setSeriesPaint(i, AUTH_COLORS[i]);
        ls.setSeriesPaint(i, AUTH_COLORS[i]);
        mDatasetsSync[i] = new TimePeriodValues(AUTH_NAMES[i]);
        tpvc.addSeries(mDatasetsSync[i]);
        mTooltipsSync[i] = new ArrayList<String>();
        mTooltipGenerators[i] = new CustomXYToolTipGenerator();
        br.setSeriesToolTipGenerator(i, mTooltipGenerators[i]);
        mTooltipGenerators[i].addToolTipSeries(mTooltipsSync[i]);

        mDatasetsSyncTickle[i] = new TimeSeries(AUTH_NAMES[i] + " tickle", FixedMillisecond.class);
        tsc.addSeries(mDatasetsSyncTickle[i]);
        ls.setSeriesShape(i, ShapeUtilities.createUpTriangle(2.5f));
    }
}