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

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

Introduction

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

Prototype

public TimeSeriesCollection() 

Source Link

Document

Constructs an empty dataset, tied to the default timezone.

Usage

From source file:edu.unibonn.kmeans.mapreduce.plotting.TimeSeriesPlotter_KMeans.java

private XYDataset createDataset(ArrayList<Sensor> sensors) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();

    for (int i = 0; i < sensors.size(); i++)
    //for (int i = 0; i < 100; i++)
    {/*  w  w  w.  j  av  a2 s.c  o  m*/
        Sensor current_sensor = sensors.get(i);
        ArrayList<Measurement> current_measurements = current_sensor.getMeasurements();

        final TimeSeries s1 = new TimeSeries("Sensor " + i, Hour.class);

        for (int j = 0; j < current_measurements.size(); j++) {
            Measurement current_measurement = current_measurements.get(j);

            LocalDateTime current_time = current_measurement.getRecord_time();

            s1.add(new Hour(current_time.getHour(), current_time.getDayOfMonth(), current_time.getMonthValue(),
                    current_time.getYear()), current_measurement.getErlang());
        }

        dataset.addSeries(s1);
    }

    dataset.setDomainIsPointsInTime(true);

    return dataset;
}

From source file:com.android.ddmuilib.net.NetworkPanel.java

/**
 * Create chart of recent network activity.
 *///from w  w  w .j a  v a  2 s.c o m
private void createChart() {

    mChart = ChartFactory.createTimeSeriesChart(null, null, null, null, false, false, false);

    // create backing datasets and series
    mRxTotalSeries = new TimeSeries("RX total");
    mTxTotalSeries = new TimeSeries("TX total");

    mRxTotalSeries.setMaximumItemAge(HISTORY_MILLIS);
    mTxTotalSeries.setMaximumItemAge(HISTORY_MILLIS);

    mTotalCollection = new TimeSeriesCollection();
    mTotalCollection.addSeries(mRxTotalSeries);
    mTotalCollection.addSeries(mTxTotalSeries);

    mRxDetailDataset = new LiveTimeTableXYDataset();
    mTxDetailDataset = new LiveTimeTableXYDataset();

    mTotalRenderer = new XYAreaRenderer(XYAreaRenderer.AREA);
    mRenderer = new StackedXYAreaRenderer2();

    final XYPlot xyPlot = mChart.getXYPlot();

    xyPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    xyPlot.setDataset(0, mTotalCollection);
    xyPlot.setDataset(1, mRxDetailDataset);
    xyPlot.setDataset(2, mTxDetailDataset);
    xyPlot.setRenderer(0, mTotalRenderer);
    xyPlot.setRenderer(1, mRenderer);
    xyPlot.setRenderer(2, mRenderer);

    // we control domain axis manually when taking samples
    mDomainAxis = xyPlot.getDomainAxis();
    mDomainAxis.setAutoRange(false);

    final NumberAxis axis = new NumberAxis();
    axis.setNumberFormatOverride(new BytesFormat(true));
    axis.setAutoRangeMinimumSize(50);
    xyPlot.setRangeAxis(axis);
    xyPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    // draw thick line to separate RX versus TX traffic
    xyPlot.addRangeMarker(new ValueMarker(0, java.awt.Color.BLACK, new java.awt.BasicStroke(2)));

    // label to indicate that positive axis is RX traffic
    final ValueMarker rxMarker = new ValueMarker(0);
    rxMarker.setStroke(new java.awt.BasicStroke(0));
    rxMarker.setLabel("RX");
    rxMarker.setLabelFont(rxMarker.getLabelFont().deriveFont(30f));
    rxMarker.setLabelPaint(java.awt.Color.LIGHT_GRAY);
    rxMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    rxMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    xyPlot.addRangeMarker(rxMarker);

    // label to indicate that negative axis is TX traffic
    final ValueMarker txMarker = new ValueMarker(0);
    txMarker.setStroke(new java.awt.BasicStroke(0));
    txMarker.setLabel("TX");
    txMarker.setLabelFont(txMarker.getLabelFont().deriveFont(30f));
    txMarker.setLabelPaint(java.awt.Color.LIGHT_GRAY);
    txMarker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
    txMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    xyPlot.addRangeMarker(txMarker);

    mChartComposite = new ChartComposite(mPanel, SWT.BORDER, mChart, ChartComposite.DEFAULT_WIDTH,
            ChartComposite.DEFAULT_HEIGHT, ChartComposite.DEFAULT_MINIMUM_DRAW_WIDTH,
            ChartComposite.DEFAULT_MINIMUM_DRAW_HEIGHT, 4096, 4096, true, true, true, true, false, true);

    final FormData data = new FormData();
    data.top = new FormAttachment(mHeader);
    data.left = new FormAttachment(0);
    data.bottom = new FormAttachment(70);
    data.right = new FormAttachment(100);
    mChartComposite.setLayoutData(data);
}

From source file:org.jfree.data.time.TimeSeriesCollectionTest.java

/**
 * This method provides a check for the bounds calculated using the
 * {@link DatasetUtilities#findDomainBounds(org.jfree.data.xy.XYDataset,
 * java.util.List, boolean)} method./*from   w  w  w.j av  a2s. c  o m*/
 */
@Test
public void testFindDomainBounds() {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    List visibleSeriesKeys = new java.util.ArrayList();
    Range r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true);
    assertNull(r);

    TimeSeries s1 = new TimeSeries("S1");
    dataset.addSeries(s1);
    visibleSeriesKeys.add("S1");
    r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true);
    assertNull(r);

    // store the current time zone
    TimeZone saved = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/Paris"));

    s1.add(new Year(2008), 8.0);
    r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true);
    assertEquals(1199142000000.0, r.getLowerBound(), EPSILON);
    assertEquals(1230764399999.0, r.getUpperBound(), EPSILON);

    TimeSeries s2 = new TimeSeries("S2");
    dataset.addSeries(s2);
    s2.add(new Year(2009), 9.0);
    s2.add(new Year(2010), 10.0);
    r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true);
    assertEquals(1199142000000.0, r.getLowerBound(), EPSILON);
    assertEquals(1230764399999.0, r.getUpperBound(), EPSILON);

    visibleSeriesKeys.add("S2");
    r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true);
    assertEquals(1199142000000.0, r.getLowerBound(), EPSILON);
    assertEquals(1293836399999.0, r.getUpperBound(), EPSILON);

    // restore the default time zone
    TimeZone.setDefault(saved);
}

From source file:org.paxle.tools.charts.impl.gui.ChartServlet.java

private JFreeChart createPPMChart() {
    /*//w  ww  .  j av a2 s  .  com
     * INIT TIME-SERIES 
     */
    final TimeSeriesCollection dataset = new TimeSeriesCollection();

    TimeSeries crawlerPPM = new TimeSeries("Crawler PPM", Minute.class);
    crawlerPPM.setMaximumItemAge(24 * 60);
    dataset.addSeries(crawlerPPM);
    this.seriesMap.put(TSERIES_PPM_CRAWLER, crawlerPPM);

    TimeSeries parserPPM = new TimeSeries("Parser PPM", Minute.class);
    parserPPM.setMaximumItemAge(24 * 60);
    dataset.addSeries(parserPPM);
    this.seriesMap.put(TSERIES_PPM_PARSER, parserPPM);

    TimeSeries indexerPPM = new TimeSeries("Indexer PPM", Minute.class);
    indexerPPM.setMaximumItemAge(24 * 60);
    dataset.addSeries(indexerPPM);
    this.seriesMap.put(TSERIES_PPM_INDEXER, indexerPPM);

    /*
     * INIT CHART
     */
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, "Time", "PPM", dataset, true, false, false);

    // change axis data format
    ((DateAxis) chart.getXYPlot().getDomainAxis()).setDateFormatOverride(new SimpleDateFormat("HH:mm"));
    chart.setBackgroundPaint(Color.WHITE);
    return chart;
}

From source file:com.jbombardier.reports.OldReportGenerator.java

private TimeSeriesCollection extractTimeSeries(Chunker chunker, Set<String> transactionNames,
        Statistic statistic) {//  w  w w.  ja va  2 s  .c o  m
    TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();
    for (String transaction : transactionNames) {
        List<Chunk> timeOrderedResults = chunker.getTimeOrderedResults(transaction);
        TimeSeries timeSeries = extractTimeSeries(timeOrderedResults, transaction, statistic);

        timeSeriesCollection.addSeries(timeSeries);
    }
    return timeSeriesCollection;
}

From source file:com.bdb.weather.display.summary.HighLowMedianTempPanel.java

/**
 * Load the data into the graph and table.
 * // ww  w .j  a v  a  2 s  . c o  m
 * @param summaryList The list of summary records to load
 * @param averages The averages to load
 */
public void loadData(List<SummaryRecord> summaryList, WeatherAverages averages) {
    highDataset = new TimeSeriesCollection();
    lowDataset = new TimeSeriesCollection();
    meanDataset = new TimeSeriesCollection();

    loadDataSeries(summaryList, lowDataset, highDataset, meanDataset, averages);

    plot.setDataset(LOW_DATASET, lowDataset);
    plot.setDataset(HIGH_DATASET, highDataset);
    plot.setDataset(MEDIAN_DATASET, meanDataset);
}

From source file:DashboardInterface.LaunchGraph.java

public void addDataset(String title, int index, int range) {
    XYSplineRenderer render = new XYSplineRenderer();
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    TimeSeries series = new TimeSeries(title);
    dataset.addSeries(series);/*ww w . ja  va 2  s  . c om*/
    XYDataset xyDataset = dataset;

    plot.setDataset(index, xyDataset);
    plot.setRenderer(index, render);

    NumberAxis axis = new NumberAxis(title);
    axis.setRange(0, range);

    plot.setRangeAxis(index, axis);
    plot.mapDatasetToRangeAxis(index, index);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRendererForDataset(xyDataset);
    renderer.setBaseShapesVisible(false);
    renderer.setBaseShapesFilled(false);
}

From source file:info.financialecology.finance.utilities.datastruct.VersatileChart.java

public JFreeChart drawTimeSeries(ArrayList<VersatileTimeSeries> atsArray) {
    JFreeChart chart;/*w  w  w  . ja  va2 s. co m*/
    ArrayList<String> visibleKeys = new ArrayList<String>();

    if (params.ticks) {
        XYSeriesCollection dataSet = new XYSeriesCollection();

        for (VersatileTimeSeries ats : atsArray) {
            XYSeries xySeries = new XYSeries(ats.getKey());
            dataSet.addSeries(xySeries);

            for (int i = 0; i < ats.getItemCount(); i++)
                xySeries.add(i, ats.getValue(i));
        }

        chart = ChartFactory.createXYLineChart(params.title, params.xLabel, params.yLabel, dataSet,
                PlotOrientation.VERTICAL, params.legend, params.toolTips, false);

        if (params.autoRange) {
            Range currentRange = dataSet.getRangeBounds(true);
            Range newRange = new Range((1 - params.autoRangePadding) * currentRange.getLowerBound(),
                    (1 + params.autoRangePadding) * currentRange.getUpperBound());
            chart.getXYPlot().getRangeAxis().setRange(newRange);
        }
    } else {
        TimeSeriesCollection dataSet = new TimeSeriesCollection();

        for (VersatileTimeSeries ats : atsArray) {
            dataSet.addSeries(ats);
            visibleKeys.add((String) ats.getKey());
        }

        chart = ChartFactory.createTimeSeriesChart(params.title, params.xLabel, params.yLabel, dataSet,
                params.legend, params.toolTips, false);

        if (params.autoRange) {
            Range currentRange = dataSet.getRangeBounds(visibleKeys, dataSet.getDomainBounds(true), true);
            Range newRange = new Range((1 - params.autoRangePadding) * currentRange.getLowerBound(),
                    (1 + params.autoRangePadding) * currentRange.getUpperBound());
            chart.getXYPlot().getRangeAxis().setRange(newRange);
        }
    }

    return chart;
}

From source file:compecon.dashboard.panel.HouseholdsPanel.java

protected ChartPanel createIncomeConsumptionSavingPanel(Currency currency) {
    TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

    timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
            .getNationalEconomyModel(currency).householdsModel.incomeModel.getTimeSeries());
    timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
            .getNationalEconomyModel(currency).householdsModel.consumptionModel.getTimeSeries());
    timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
            .getNationalEconomyModel(currency).householdsModel.savingModel.getTimeSeries());

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Consumption & Saving", "Date",
            "Consumption & Saving", timeSeriesCollection, true, true, false);
    configureChart(chart);/*from  w w w .  j  ava2 s  .  co  m*/
    return new ChartPanel(chart);
}

From source file:lu.lippmann.cdb.common.gui.ts.TimeSeriesChartUtil.java

public static ChartPanel buildChartPanelForAllAttributes(final Instances dataSet, final boolean multAxis,
        final int dateIdx, final Color color, final Collection<XYAnnotation> annotations) {
    final TimeSeriesCollection tsDataset = new TimeSeriesCollection();
    final JFreeChart tsChart = ChartFactory.createTimeSeriesChart("", "Time", "Value", tsDataset, true, true,
            false);/*from  w  w  w  .j  a  va 2  s  .c om*/
    tsChart.getXYPlot().setBackgroundPaint(Color.WHITE);

    // optimized renderer to avoid to print all points
    tsChart.getXYPlot().setRenderer(new SamplingXYLineRenderer());
    //tsChart.getXYPlot().setRenderer(new XYStepRenderer());

    if (color == null) {
        for (int i = 0; i < dataSet.numAttributes() - 1; i++) {
            final String attrName = dataSet.attribute(i).name();
            tsChart.getXYPlot().getRenderer().setSeriesPaint(i, ColorHelper.getColorForAString(attrName));
        }
    } else {
        tsChart.getXYPlot().getRenderer().setSeriesPaint(0, color);
    }

    if (annotations != null) {
        for (final XYAnnotation aa : annotations)
            tsChart.getXYPlot().addAnnotation(aa);
    }

    if (multAxis)
        fillWithMultipleAxis(dataSet, dateIdx, tsDataset, tsChart);
    else
        fillWithSingleAxis(dataSet, dateIdx, tsDataset);

    final ChartPanel cp = new ChartPanel(tsChart, true);
    if (dataSet.numAttributes() <= 2)
        cp.setBorder(new TitledBorder(dataSet.attribute(0).name()));
    return cp;
}