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) 

Source Link

Document

Creates a new (empty) time series.

Usage

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

/**
 * Creates a new demo./*from ww w  . j  av a  2  s  .  c  o m*/
 *
 * @param title  the frame title.
 */
public XYAreaChartDemo2(final String title) {

    super(title);

    final TimeSeries series1 = new TimeSeries("Random 1");
    double value = 0.0;
    Day day = new Day();
    for (int i = 0; i < 200; i++) {
        value = value + Math.random() - 0.5;
        series1.add(day, value);
        day = (Day) day.next();
    }

    final TimeSeriesCollection dataset = new TimeSeriesCollection(series1);

    final JFreeChart chart = createChart(dataset);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:org.sonar.server.charts.jruby.TrendsChart.java

public void initSerie(Long serieId, String legend, boolean isPercent) {
    TimeSeries series = new TimeSeries(legend);

    int index = seriesById.size();
    seriesById.put(serieId, series);//from w ww.ja v a2 s .  co  m

    TimeSeriesCollection timeSeriesColl = new TimeSeriesCollection();
    timeSeriesColl.addSeries(series);
    plot.setDataset(index, timeSeriesColl);

    if (isPercent) {
        if (percentAxisId == -1) {
            NumberAxis rangeAxis = new NumberAxis();
            rangeAxis.setNumberFormatOverride(new DecimalFormat("0'%'"));
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            rangeAxis.setUpperBound(100.0);
            rangeAxis.setLowerBound(0.0);
            plot.setRangeAxisLocation(index, AxisLocation.TOP_OR_LEFT);
            plot.setRangeAxis(index, rangeAxis);
            plot.mapDatasetToRangeAxis(index, index);
            percentAxisId = index;

        } else {
            plot.mapDatasetToRangeAxis(index, percentAxisId);
        }
    } else {
        NumberAxis rangeAxis = new NumberAxis(displayLegend ? legend : null);
        rangeAxis.setAutoRangeIncludesZero(false);
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        rangeAxis.setAutoRangeMinimumSize(2.0);
        plot.setRangeAxisLocation(index, AxisLocation.TOP_OR_RIGHT);
        plot.setRangeAxis(index, rangeAxis);
        plot.mapDatasetToRangeAxis(index, index);
    }

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer.setSeriesPaint(0, COLORS[index % COLORS.length]);
    plot.setRenderer(index, renderer);
}

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

private static XYDataset createDataset2006() {
    TimeSeries timeseries = new TimeSeries("Sales 2006");
    timeseries.add(new Month(1, 2006), 100D);
    timeseries.add(new Month(2, 2006), 102.3D);
    timeseries.add(new Month(3, 2006), 105.7D);
    timeseries.add(new Month(4, 2006), 104.2D);
    timeseries.add(new Month(5, 2006), 114.7D);
    timeseries.add(new Month(6, 2006), 121.7D);
    timeseries.add(new Month(7, 2006), 155.59999999999999D);
    timeseries.add(new Month(8, 2006), 143.19999999999999D);
    timeseries.add(new Month(9, 2006), 131.90000000000001D);
    timeseries.add(new Month(10, 2006), 120D);
    timeseries.add(new Month(11, 2006), 109.90000000000001D);
    timeseries.add(new Month(12, 2006), 99.599999999999994D);
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    timeseriescollection.addSeries(timeseries);
    timeseriescollection.setXPosition(TimePeriodAnchor.MIDDLE);
    return timeseriescollection;
}

From source file:com.stableapps.anglewraparounddemo.AngleWrapDemoMain.java

/**
 * Creates a sample dataset./*from w w  w . ja  va 2  s .  com*/
 *
 * @param count the item count.
 *
 * @return the dataset.
 */
private XYDataset createAngleDataset(final int count) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    final TimeSeries s1 = new TimeSeries("Angle (In Degrees)");
    RegularTimePeriod start = new Minute();
    double direction = 180.0;
    for (int i = 0; i < count; i++) {
        s1.add(start, direction);
        start = start.next();
        direction = direction + (Math.random() - 0.45) * 15.0;
        if (direction < 0.0) {
            direction = direction + 360.0;
        } else if (direction > 360.0) {
            direction = direction - 360.0;
        }
    }
    dataset.addSeries(s1);
    return dataset;
}

From source file:com.bdb.weather.display.freeplot.FreePlotSeries.java

/**
 * Constructor.//from w w w  . j  a  v a  2s  .c  om
 * 
 * @param name The name of the series, this must match the name of the corresponding control
 * @param seriesIndex The index of this series from a JFreePlot point of view
 * @param paint The Paint to be used to draw this series
 * @param stroke The Stroke to be used to draw this series
 * @param getDataMethod The method used to get the data of this series (Reflection used)
 * @param getTimeMethod The method used to get the time of the data of this series (Reflection used)
 * @param timePeriod The time increment of this data.
 */
public FreePlotSeries(String name, int seriesIndex, Color paint, Stroke stroke,
        Function<T, Measurement> getDataMethod, Function<T, TemporalAccessor> getTimeMethod,
        Class<?> timePeriod) {
    this.name = name;
    this.seriesIndex = seriesIndex;
    this.paint = paint;
    this.stroke = stroke;
    this.series = new TimeSeries(name);
    this.getDataMethod = getDataMethod;
    //this.dataMethodArgs = dataMethodArgs;
    this.getTimeMethod = getTimeMethod;
    this.timePeriod = timePeriod;
}

From source file:Perfil_Deportivo.TimeSeriesChartDemo1.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset.//from   w  ww .ja v  a2  s. co  m
 */
private static XYDataset createDataset() {

    TimeSeries s1 = new TimeSeries("L&G European Index Trust");

    SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
    String strFecha = "1/01/2000";
    Date fechaDate = null;
    try {
        fechaDate = formato.parse(strFecha);
        // s1.add(new ,2);
    } catch (ParseException ex) {

    }

    //s1.add(new Week(1, 1), null);
    s1.add(new Month(fechaDate), 167.3);
    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");
    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);

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);
    dataset.addSeries(s2);
    dataset.addSeries(s3);

    return dataset;

}

From source file:binky.reportrunner.ui.actions.admin.GetAuditChartAction.java

@Override
@PreAuthorize("hasRole('ROLE_ADMIN')")
public String execute() throws Exception {

    // do some stuff and get a chart going
    // DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    TimeSeriesCollection dataSet = new TimeSeriesCollection();
    List<RunnerHistoryEvent> events = auditService.getSuccessEvents(module, new Date(fromDate),
            new Date(toDate));
    Map<String, TimeSeries> serieses = new HashMap<String, TimeSeries>();
    for (RunnerHistoryEvent e : events) {
        TimeSeries s = serieses.get(e.getMethod());
        if (s == null) {
            s = new TimeSeries(e.getMethod());
            serieses.put(e.getMethod(), s);
        }/*from  w  ww  .  j ava 2 s.com*/
        s.addOrUpdate(new Millisecond(e.getTimeStamp()), e.getRunTime());
    }
    for (TimeSeries s : serieses.values()) {
        dataSet.addSeries(s);
    }
    chart = ChartFactory.createTimeSeriesChart(module, "", "run time (ms)", dataSet, true, false, false);

    // .createLineChart("","","Run Time (ms)",dataSet,PlotOrientation.VERTICAL,
    // true,false,false);
    XYPlot linePlot = (XYPlot) chart.getPlot();
    linePlot.setDomainGridlinesVisible(true);
    linePlot.setRangeGridlinesVisible(true);
    linePlot.setRangeGridlinePaint(Color.black);
    linePlot.setDomainGridlinePaint(Color.black);
    TextTitle subTitle = new TextTitle("Successful Executions");
    subTitle.setFont(new Font("Arial", Font.ITALIC, 10));
    chart.addSubtitle(subTitle);
    chart.getTitle().setFont(new Font("Arial", Font.BOLD, 12));

    DateAxis axis = (DateAxis) linePlot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("hh:mm:ss dd-MM-yyyy"));

    XYItemRenderer r = linePlot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    chart.setAntiAlias(true);
    chart.setTextAntiAlias(true);
    return SUCCESS;
}

From source file:org.hxzon.demo.jfreechart.DatasetVisibleDemo.java

private static XYDataset createDataset() {

    TimeSeries s1 = new TimeSeries(series1Name);
    s1.add(new Month(1, 2001), 181.8);
    s1.add(new Month(2, 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(9, 2001), 148.3);
    s1.add(new Month(10, 2001), 153.9);
    s1.add(new Month(11, 2001), 142.7);
    s1.add(new Month(12, 2001), 123.2);
    s1.add(new Month(1, 2002), 131.8);
    s1.add(new Month(2, 2002), 139.6);
    s1.add(new Month(3, 2002), 142.9);
    s1.add(new Month(4, 2002), 138.7);
    s1.add(new Month(6, 2002), 137.3);
    s1.add(new Month(7, 2002), 143.9);
    s1.add(new Month(8, 2002), 139.8);
    s1.add(new Month(9, 2002), 137.0);
    s1.add(new Month(10, 2002), 132.8);

    TimeSeries s2 = new TimeSeries(series2Name);
    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(series3Name);
    s3.add(new Month(2, 2001), 1129.6);
    s3.add(new Month(3, 2001), 1123.2);
    s3.add(new Month(4, 2001), 1117.2);
    s3.add(new Month(5, 2001), 1124.1);
    s3.add(new Month(6, 2001), 1122.6);
    s3.add(new Month(7, 2001), 1119.2);
    s3.add(new Month(8, 2001), 1116.5);
    s3.add(new Month(9, 2001), 1112.7);
    s3.add(new Month(10, 2001), 1101.5);
    s3.add(new Month(11, 2001), 1106.1);
    s3.add(new Month(12, 2001), 1110.3);
    s3.add(new Month(1, 2002), 1111.7);
    s3.add(new Month(2, 2002), 1111.0);
    s3.add(new Month(3, 2002), 1109.6);
    s3.add(new Month(4, 2002), 1113.2);
    s3.add(new Month(5, 2002), 1111.6);
    s3.add(new Month(6, 2002), 1108.8);
    s3.add(new Month(7, 2002), 1101.6);

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s3);//from w w w.j ava  2 s  . com
    dataset.addSeries(s2);
    dataset.addSeries(s1);

    return dataset;
}

From source file:diplomawork.model.ViewForDiagram.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset.//  w w w .jav  a  2 s.c o m
 */
private TimeSeriesCollection createDataset() {
    timeSeries = new TimeSeries("EUR/USD");
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(timeSeries);
    return dataset;
}

From source file:org.hxzon.demo.jfreechart.DatasetVisibleDemo3.java

private static XYDataset createDataset1() {
    boolean notify = false;

    TimeSeries s1 = new TimeSeries(series1Name);
    s1.add(new Month(1, 2001), 181.8, notify);
    s1.add(new Month(2, 2001), 167.3, notify);
    s1.add(new Month(4, 2001), 153.8, notify);
    s1.add(new Month(5, 2001), 167.6, notify);
    s1.add(new Month(6, 2001), 158.8, notify);
    s1.add(new Month(9, 2001), 148.3, notify);
    s1.add(new Month(10, 2001), 153.9, notify);
    s1.add(new Month(11, 2001), 142.7, notify);
    s1.add(new Month(12, 2001), 123.2, notify);
    s1.add(new Month(1, 2002), 131.8, notify);
    s1.add(new Month(2, 2002), 139.6, notify);
    s1.add(new Month(3, 2002), 142.9, notify);
    s1.add(new Month(4, 2002), 138.7, notify);
    s1.add(new Month(6, 2002), 137.3, notify);
    s1.add(new Month(7, 2002), 143.9, notify);
    s1.add(new Month(8, 2002), 139.8, notify);
    s1.add(new Month(9, 2002), 137.0, notify);
    s1.add(new Month(10, 2002), 132.8, notify);

    TimeSeries s2 = new TimeSeries(series2Name);
    s2.add(new Month(2, 2001), 129.6, notify);
    s2.add(new Month(3, 2001), 123.2, notify);
    s2.add(new Month(4, 2001), 117.2, notify);
    s2.add(new Month(5, 2001), 124.1, notify);
    s2.add(new Month(6, 2001), 122.6, notify);
    s2.add(new Month(7, 2001), 119.2, notify);
    s2.add(new Month(8, 2001), 116.5, notify);
    s2.add(new Month(9, 2001), 112.7, notify);
    s2.add(new Month(10, 2001), 101.5, notify);
    s2.add(new Month(11, 2001), 106.1, notify);
    s2.add(new Month(12, 2001), 110.3, notify);
    s2.add(new Month(1, 2002), 111.7, notify);
    s2.add(new Month(2, 2002), 111.0, notify);
    s2.add(new Month(3, 2002), 109.6, notify);
    s2.add(new Month(4, 2002), 113.2, notify);
    s2.add(new Month(5, 2002), 111.6, notify);
    s2.add(new Month(6, 2002), 108.8, notify);
    s2.add(new Month(7, 2002), 101.6, notify);

    TimeSeries s3 = new TimeSeries(series3Name);
    s3.add(new Month(2, 2001), 1129.6, notify);
    s3.add(new Month(3, 2001), 1123.2, notify);
    s3.add(new Month(4, 2001), 1117.2, notify);
    s3.add(new Month(5, 2001), 1124.1, notify);
    s3.add(new Month(6, 2001), 1122.6, notify);
    s3.add(new Month(7, 2001), 1119.2, notify);
    s3.add(new Month(8, 2001), 1116.5, notify);
    s3.add(new Month(9, 2001), 1112.7, notify);
    s3.add(new Month(10, 2001), 1101.5, notify);
    s3.add(new Month(11, 2001), 1106.1, notify);
    s3.add(new Month(12, 2001), 1110.3, notify);
    s3.add(new Month(1, 2002), 1111.7, notify);
    s3.add(new Month(2, 2002), 1111.0, notify);
    s3.add(new Month(3, 2002), 1109.6, notify);
    s3.add(new Month(4, 2002), 1113.2, notify);
    s3.add(new Month(5, 2002), 1111.6, notify);
    s3.add(new Month(6, 2002), 1108.8, notify);
    s3.add(new Month(7, 2002), 1101.6, notify);

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

    return dataset;
}