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:edu.ucla.stat.SOCR.chart.demo.XYBarChartDemo2.java

protected IntervalXYDataset createDataset(boolean isDemo) {
    if (isDemo) {
        TimeSeries series1 = new TimeSeries("Series 1", Day.class);
        series1.add(new Day(1, 1, 2003), 54.3);
        series1.add(new Day(2, 1, 2003), 20.3);
        series1.add(new Day(3, 1, 2003), 43.4);
        series1.add(new Day(4, 1, 2003), -12.0);

        TimeSeries series2 = new TimeSeries("Series 2", Day.class);
        series2.add(new Day(1, 1, 2003), 8.0);
        series2.add(new Day(2, 1, 2003), 16.0);
        series2.add(new Day(3, 1, 2003), 21.0);
        series2.add(new Day(4, 1, 2003), 5.0);

        TimeSeriesCollection dataset = new TimeSeriesCollection();
        //dataset.setDomainIsPointsInTime(false);
        dataset.addSeries(series1);/*w w w  .j  ava2s. c o  m*/
        dataset.addSeries(series2);
        return dataset;
    } else {
        setArrayFromTable();
        String[][] x = new String[xyLength][independentVarLength];
        double[][] y = new double[xyLength][dependentVarLength];
        int[][] skipy = new int[xyLength][dependentVarLength];

        for (int index = 0; index < independentVarLength; index++)
            for (int i = 0; i < xyLength; i++)
                x[i][index] = indepValues[i][index];

        for (int index = 0; index < dependentVarLength; index++)
            for (int i = 0; i < xyLength; i++) {
                if (depValues[i][index] == null || depValues[i][index].length() == 0)
                    skipy[i][index] = 1;
                else
                    y[i][index] = Double.parseDouble(depValues[i][index]);
            }

        // create the dataset... 
        TimeSeriesCollection collection = new TimeSeriesCollection();
        TimeSeries series;

        for (int ind = 0; ind < independentVarLength; ind++) {
            int start_ind = independentHeaders[ind].lastIndexOf(":");
            if (start_ind < 0)
                start_ind = 0;

            String serieName = independentHeaders[ind].substring(0, start_ind);
            if (serieName.length() == 0)
                serieName = "Serie" + ind;

            series = new TimeSeries(serieName, Day.class);
            //TimeSeries("Executions", "Year", "Count", Year.class);

            for (int i = 0; i < xyLength; i++) {
                if (x[i][ind] != null && skipy[i][ind] != 1) {
                    series.add(DateParser.parseDay(x[i][ind]), y[i][ind]);
                }
            }
            //collection.setDomainIsPointsInTime(false);
            collection.addSeries(series);
        }
        return collection;

    }
}

From source file:net.sourceforge.openforecast.examples.ExponentialSmoothingChartDemo.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 * @return the dataset./*from w  w w. j  a  v  a2 s .  c  om*/
 */
public XYDataset createDataset() {
    TimeSeries observations = new TimeSeries("Quarterly Sales", Quarter.class);

    observations.add(new Quarter(1, 1990), 362.0);
    observations.add(new Quarter(2, 1990), 385.0);
    observations.add(new Quarter(3, 1990), 432.0);
    observations.add(new Quarter(4, 1990), 341.0);
    observations.add(new Quarter(1, 1991), 382.0);
    observations.add(new Quarter(2, 1991), 409.0);
    observations.add(new Quarter(3, 1991), 498.0);
    observations.add(new Quarter(4, 1991), 387.0);
    observations.add(new Quarter(1, 1992), 473.0);
    observations.add(new Quarter(2, 1992), 513.0);
    observations.add(new Quarter(3, 1992), 582.0);
    observations.add(new Quarter(4, 1992), 474.0);
    observations.add(new Quarter(1, 1993), 544.0);
    observations.add(new Quarter(2, 1993), 582.0);
    observations.add(new Quarter(3, 1993), 681.0);
    observations.add(new Quarter(4, 1993), 557.0);
    observations.add(new Quarter(1, 1994), 628.0);
    observations.add(new Quarter(2, 1994), 707.0);
    observations.add(new Quarter(3, 1994), 773.0);
    observations.add(new Quarter(4, 1994), 592.0);
    observations.add(new Quarter(1, 1995), 627.0);
    observations.add(new Quarter(2, 1995), 725.0);
    observations.add(new Quarter(3, 1995), 854.0);
    observations.add(new Quarter(4, 1995), 661.0);

    fc = new TimeSeries("Forecast values", Quarter.class);
    fc.add(new Quarter(1, 1990), 0.0);
    fc.add(new Quarter(2, 1990), 0.0);
    fc.add(new Quarter(3, 1990), 0.0);
    fc.add(new Quarter(4, 1990), 0.0);
    fc.add(new Quarter(1, 1991), 0.0);
    fc.add(new Quarter(2, 1991), 0.0);
    fc.add(new Quarter(3, 1991), 0.0);
    fc.add(new Quarter(4, 1991), 0.0);
    fc.add(new Quarter(1, 1992), 0.0);
    fc.add(new Quarter(2, 1992), 0.0);
    fc.add(new Quarter(3, 1992), 0.0);
    fc.add(new Quarter(4, 1992), 0.0);
    fc.add(new Quarter(1, 1993), 0.0);
    fc.add(new Quarter(2, 1993), 0.0);
    fc.add(new Quarter(3, 1993), 0.0);
    fc.add(new Quarter(4, 1993), 0.0);
    fc.add(new Quarter(1, 1994), 0.0);
    fc.add(new Quarter(2, 1994), 0.0);
    fc.add(new Quarter(3, 1994), 0.0);
    fc.add(new Quarter(4, 1994), 0.0);
    fc.add(new Quarter(1, 1995), 0.0);
    fc.add(new Quarter(2, 1995), 0.0);
    fc.add(new Quarter(3, 1995), 0.0);
    fc.add(new Quarter(4, 1995), 0.0);
    fc.add(new Quarter(1, 1996), 0.0);
    fc.add(new Quarter(2, 1996), 0.0);
    fc.add(new Quarter(3, 1996), 0.0);
    fc.add(new Quarter(4, 1996), 0.0);
    fc.add(new Quarter(1, 1997), 0.0);
    fc.add(new Quarter(2, 1997), 0.0);
    fc.add(new Quarter(3, 1997), 0.0);
    fc.add(new Quarter(4, 1997), 0.0);
    fc.add(new Quarter(1, 1998), 0.0);
    fc.add(new Quarter(2, 1998), 0.0);
    fc.add(new Quarter(3, 1998), 0.0);
    fc.add(new Quarter(4, 1998), 0.0);

    DataSet initDataSet = getDataSet(observations, 0, 100);
    initDataSet.setTimeVariable("t");
    initDataSet.setPeriodsPerYear(4);

    // Get "best fit" simple exponential smoothing model
    ForecastingModel sesModel = SimpleExponentialSmoothingModel.getBestFitModel(initDataSet);
    TimeSeries sesSeries = getForecastTimeSeries(sesModel, initDataSet, 0, 30, "Simple Exponential Smoothing");

    // Get "best fit" double exponential smoothing model
    ForecastingModel desModel = DoubleExponentialSmoothingModel.getBestFitModel(initDataSet);
    TimeSeries desSeries = getForecastTimeSeries(desModel, initDataSet, 0, 30, "Double Exponential Smoothing");

    // Get "best fit" triple exponential smoothing model
    ForecastingModel tesModel = TripleExponentialSmoothingModel.getBestFitModel(initDataSet);
    TimeSeries tesSeries = getForecastTimeSeries(tesModel, initDataSet, 5, 28, "Triple Exponential Smoothing");

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(observations);
    dataset.addSeries(sesSeries);
    dataset.addSeries(desSeries);
    dataset.addSeries(tesSeries);

    return dataset;
}

From source file:edu.ucla.stat.SOCR.chart.demo.CrosshairDemo3.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return the dataset.//from  w ww.j  a  v a2 s .  c  o m
 */
protected XYDataset createDataset(boolean isDemo) {
    if (isDemo) {
        chartTitle = "Legal & General Unit Trust Prices";
        domainLabel = "Date";
        rangeLabel = "Price Per Unit";
        TimeSeries s1 = new TimeSeries("L&G European Index Trust", Month.class);
        s1.add(new Month(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", Month.class);
        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);
        dataset.addSeries(s2);

        //  dataset.setDomainIsPointsInTime(true);

        return dataset;
    } else {
        super.setArrayFromTable();
        String[][] x = new String[xyLength][independentVarLength];
        double[][] y = new double[xyLength][dependentVarLength];
        int[][] skipy = new int[xyLength][dependentVarLength];

        for (int index = 0; index < independentVarLength; index++)
            for (int i = 0; i < xyLength; i++)
                x[i][index] = indepValues[i][index];

        for (int index = 0; index < dependentVarLength; index++)
            for (int i = 0; i < xyLength; i++)
                if (depValues[i][index] == null || depValues[i][index].length() == 0)
                    skipy[i][index] = 1;
                else
                    y[i][index] = Double.parseDouble(depValues[i][index]);

        // create the dataset... 
        TimeSeriesCollection collection = new TimeSeriesCollection();
        TimeSeries series;

        for (int ind = 0; ind < independentVarLength; ind++) {
            if (independentHeaders[ind].indexOf(":") != -1)
                series = new TimeSeries(
                        independentHeaders[ind].substring(0, independentHeaders[ind].indexOf(":")),
                        Month.class);
            else
                series = new TimeSeries(independentHeaders[ind], Month.class);
            //TimeSeries("Executions", "Year", "Count", Year.class);

            for (int i = 0; i < xyLength; i++) {
                if (x[i][ind] != null && y[i][ind] != 1)
                    series.add(DateParser.parseMonth(x[i][ind]), y[i][ind]);
            }
            //collection.setDomainIsPointsInTime(false);
            collection.addSeries(series);
        }
        return collection;
    }

}

From source file:EHRAppointment.ChartPanelDraw.java

private XYDataset createTimeDataset() {
    TimeSeries s1 = new TimeSeries(type); //Creating time series plot for X

    if (type.equals("Weight")) {

        for (Vitals vital : result) {
            s1.add(new Day(vital.getDateTime().getDate(), vital.getDateTime().getMonth() + 1,
                    vital.getDateTime().getYear() + 1900), vital.getWeight());
        }/*from  www.j  av  a2s  .  c om*/
    } else if (type.equals("Height")) {
        for (Vitals vital : result) {
            s1.add(new Day(vital.getDateTime().getDate(), vital.getDateTime().getMonth() + 1,
                    vital.getDateTime().getYear() + 1900), vital.getHeight());
        }
    } else if (type.equals("BP Systolic")) {
        for (Vitals vital : result) {
            s1.add(new Day(vital.getDateTime().getDate(), vital.getDateTime().getMonth() + 1,
                    vital.getDateTime().getYear() + 1900), vital.getBpSystolic());
        }
    } else if (type.equals("BP Diastolic")) {
        for (Vitals vital : result) {
            s1.add(new Day(vital.getDateTime().getDate(), vital.getDateTime().getMonth() + 1,
                    vital.getDateTime().getYear() + 1900), vital.getBpDiastolic());
        }
    } else if (type.equals("Pulse")) {
        for (Vitals vital : result) {
            s1.add(new Day(vital.getDateTime().getDate(), vital.getDateTime().getMonth() + 1,
                    vital.getDateTime().getYear() + 1900), vital.getPulse());
        }
    } else if (type.equals("Temperature")) {
        for (Vitals vital : result) {
            s1.add(new Day(vital.getDateTime().getDate(), vital.getDateTime().getMonth() + 1,
                    vital.getDateTime().getYear() + 1900), vital.getTemperature());
        }
    } else if (type.equals("Oxygen Saturation")) {
        for (Vitals vital : result) {
            s1.add(new Day(vital.getDateTime().getDate(), vital.getDateTime().getMonth() + 1,
                    vital.getDateTime().getYear() + 1900), vital.getOxygenSaturation());
        }
    } else if (type.equals("BMI")) {
        for (Vitals vital : result) {
            s1.add(new Day(vital.getDateTime().getDate(), vital.getDateTime().getMonth() + 1,
                    vital.getDateTime().getYear() + 1900), vital.getBmi());
        }
    } else {
        System.out.println("Type select vital error");
    }

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);
    return dataset;
}

From source file:CargarEntrenamiento.grafica2.java

public void grafica1() {
    s1.add(new Month(2, 2001), 181.8);
    //s1.add(new Week(1, 1), null);
    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);

    TimeSeries s3 = new TimeSeries("andres2255");
    s3.add(new Month(2, 2001), 129.6);

    s3.add(new Month(10, 2001), 106.1);
    s3.add(new Month(1, 2002), 111.7);
    s3.add(new Month(2, 2002), 111.0);
    datos.addSeries(s1);/*  www .jav  a2s  . c  o  m*/
    datos.addSeries(s2);
    datos.addSeries(s3);

    grafica = ChartFactory.createTimeSeriesChart("titulo", "etiquetas X", "etiquetaY", datos, true, true,
            false);
    /// 
    grafica.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) grafica.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);
        renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

}

From source file:CargarEntrenamiento.grafica2.java

public void iejmplo() {

    s1.add(new Month(2, 2001), 181.8);
    //s1.add(new Week(1, 1), null);
    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);

    TimeSeries s3 = new TimeSeries("andres2255");
    s3.add(new Month(2, 2001), 129.6);

    s3.add(new Month(10, 2001), 106.1);
    s3.add(new Month(1, 2002), 111.7);
    s3.add(new Month(2, 2002), 111.0);
    datos.addSeries(s1);//from   w w w .ja v a 2  s . c om
    datos.addSeries(s2);
    datos.addSeries(s3);

    grafica = ChartFactory.createTimeSeriesChart("titulo", "etiquetas X", "etiquetaY", datos, true, true,
            false);
    /// 
    grafica.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) grafica.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);
        renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
}

From source file:DashboardInterface.LaunchGraph.java

private XYDataset createDataset4(int offset) {
    long dateMili = 0L;

    TimeSeries s1 = new TimeSeries("");
    s1.add(new Second(new Date(dateMili)), 110);
    s1.add(new Second(new Date(dateMili + offset)), 110);
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);//from  w ww.ja  v  a 2 s. co  m

    return dataset;

}

From source file:imc.graficaIMC.java

public void grafica1() {
    TimeSeries s1 = new TimeSeries("Entrenamiento Actual");

    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);

    TimeSeries s3 = new TimeSeries("andres2255");
    s3.add(new Month(2, 2001), 129.6);

    s3.add(new Month(10, 2001), 106.1);
    s3.add(new Month(1, 2002), 111.7);
    s3.add(new Month(2, 2002), 111.0);
    datos.addSeries(s1);//from   ww w  . ja  v a2s  . co m
    datos.addSeries(s2);
    datos.addSeries(s3);

}

From source file:edu.ucla.stat.SOCR.chart.demo.CrosshairDemo1.java

/**
 * Creates a sample dataset./*from  w  w w.jav  a 2 s . c om*/
 * 
 * @param name  the dataset name.
 * @param base  the starting value.
 * @param start  the starting period.
 * @param count  the number of values to generate.
 *
 * @return The dataset.
 */
protected XYDataset createDataset(boolean isDemo) {
    if (isDemo) {
        String name = "Random 1";
        double base = 100.0;
        RegularTimePeriod start = new Minute();
        int count = 200;

        TimeSeries series = new TimeSeries(name, start.getClass());
        RegularTimePeriod period = start;
        double value = base;
        for (int i = 0; i < count; i++) {
            series.add(period, value);
            period = period.next();
            value = value * (1 + (Math.random() - 0.495) / 10.0);
        }

        TimeSeriesCollection dataset = new TimeSeriesCollection();
        dataset.addSeries(series);

        return dataset;
    } else {
        super.setArrayFromTable();
        String[][] x = new String[xyLength][independentVarLength];
        double[][] y = new double[xyLength][dependentVarLength];
        int[][] skipy = new int[xyLength][dependentVarLength];

        for (int index = 0; index < independentVarLength; index++)
            for (int i = 0; i < xyLength; i++)
                x[i][index] = indepValues[i][index];

        for (int index = 0; index < dependentVarLength; index++)
            for (int i = 0; i < xyLength; i++)
                if (depValues[i][index] == null || depValues[i][index].length() == 0)
                    skipy[i][index] = 1;
                else
                    y[i][index] = Double.parseDouble(depValues[i][index]);

        // create the dataset... 
        TimeSeriesCollection collection = new TimeSeriesCollection();
        TimeSeries series;

        for (int ind = 0; ind < independentVarLength; ind++) {
            if (independentHeaders[ind].indexOf(":") != -1)
                series = new TimeSeries(
                        independentHeaders[ind].substring(0, independentHeaders[ind].indexOf(":")),
                        Minute.class);
            else
                series = new TimeSeries(independentHeaders[ind], Minute.class);
            //TimeSeries("Executions", "Year", "Count", Year.class);

            for (int i = 0; i < xyLength; i++) {
                if (x[i][ind] != null && y[i][ind] != 1)
                    series.add(DateParser.parseMinute(x[i][ind]), y[i][ind]);
            }
            //   collection.setDomainIsPointsInTime(false);
            collection.addSeries(series);
        }
        return collection;

    }

}

From source file:imc.graficaIMC.java

public void iejmplo() {
    TimeSeries s1 = new TimeSeries("Entrenamiento Actual");
    s1.add(new Month(2, 2001), 181.8);
    //s1.add(new Week(1, 1), null);
    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);

    TimeSeries s3 = new TimeSeries("andres2255");
    s3.add(new Month(2, 2001), 129.6);

    s3.add(new Month(10, 2001), 106.1);
    s3.add(new Month(1, 2002), 111.7);
    s3.add(new Month(2, 2002), 111.0);
    datos.addSeries(s1);/*from   w ww.java 2s.com*/
    datos.addSeries(s2);
    datos.addSeries(s3);

    grafica = ChartFactory.createTimeSeriesChart("titulo", "etiquetas X", "etiquetaY", datos, true, true,
            false);
    /// 
    grafica.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) grafica.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);
        renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
}