Search in sources :

Example 36 with TimeSeries

use of org.jfree.data.time.TimeSeries in project AndrOBD by fr3ts0n.

the class ObdDataPlotter method setGraphTime.

/**
 * Setter for property graphTime.
 *
 * @param graphTime New value of property graphTime.
 */
@SuppressWarnings("rawtypes")
public synchronized void setGraphTime(int graphTime) {
    TimeSeries currSer;
    TimeSeriesCollection currDs;
    XYPlot currPlot = (XYPlot) chart.getPlot();
    this.graphTime = graphTime;
    // lop through all datasets
    for (int i = currPlot.getDatasetCount(); i >= 0; --i) {
        currDs = (TimeSeriesCollection) currPlot.getDataset(i);
        // Update all series within dataset
        Iterator it = currDs.getSeries().iterator();
        while (it.hasNext()) {
            currSer = (TimeSeries) it.next();
            currSer.setMaximumItemAge(graphTime);
        }
    }
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) Iterator(java.util.Iterator) Paint(java.awt.Paint)

Example 37 with TimeSeries

use of org.jfree.data.time.TimeSeries in project AndrOBD by fr3ts0n.

the class ObdDataPanel method btnClearHistActionPerformed.

// </editor-fold>//GEN-END:initComponents
private // GEN-FIRST:event_btnClearHistActionPerformed
void btnClearHistActionPerformed(// GEN-FIRST:event_btnClearHistActionPerformed
java.awt.event.ActionEvent evt) {
    // GEN-HEADEREND:event_btnClearHistActionPerformed
    TimeSeries ts;
    Iterator<TimeSeries> it = selPids.values().iterator();
    while (it.hasNext()) {
        ts = it.next();
        ts.clear();
    }
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries)

Example 38 with TimeSeries

use of org.jfree.data.time.TimeSeries in project AndrOBD by fr3ts0n.

the class ObdDataPanel method pvChanged.

/**
 * handle changes in the process var(s)
 *
 * @param event Process var event to be handled
 */
public void pvChanged(PvChangeEvent event) {
    TimeSeries ts;
    EcuDataPv pv;
    switch(event.getType()) {
        case PvChangeEvent.PV_MODIFIED:
            pv = (EcuDataPv) event.getValue();
            if ((ts = selPids.get(getPvId(pv))) != null)
                try {
                    ts.addOrUpdate(new Second(), ((Number) pv.get(EcuDataPv.FID_VALUE)).floatValue());
                } catch (Exception e) {
                    ProcessVar.log.log(Level.SEVERE, "", e);
                }
            break;
        case PvChangeEvent.PV_DELETED:
            // remove from selectable PIDs
            pv = (EcuDataPv) event.getValue();
            selPids.remove(pv);
            break;
        case PvChangeEvent.PV_CLEARED:
            // remove all from selectable PIDs
            selPids.clear();
            break;
        case PvChangeEvent.PV_ADDED:
            if ((event.getValue() instanceof EcuDataPv)) {
                pv = (EcuDataPv) event.getValue();
                addDataSeries(pv);
            } else if ((event.getValue() instanceof Object[])) {
                for (Object currPv : (Object[]) event.getValue()) {
                    addDataSeries((ProcessVar) currPv);
                }
            }
            break;
    }
    // update table column widths
    updateColumnWidths();
}
Also used : EcuDataPv(com.fr3ts0n.ecu.EcuDataPv) TimeSeries(org.jfree.data.time.TimeSeries) ProcessVar(com.fr3ts0n.pvs.ProcessVar) Second(org.jfree.data.time.Second)

Example 39 with TimeSeries

use of org.jfree.data.time.TimeSeries in project xwiki-platform by xwiki.

the class TimeSeriesCollectionFactory method create.

public XYDataset create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException {
    String dataSeries = params.getString(ChartParams.SERIES);
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    Class timePeriodClass = params.getClass(ChartParams.TIME_PERIOD_CLASS);
    if (timePeriodClass == null) {
        timePeriodClass = Day.class;
    }
    DateFormat format = params.getDateFormat(ChartParams.DATE_FORMAT);
    if (format == null) {
        format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
    }
    if (dataSeries.equals("columns")) {
        if (!dataSource.hasHeaderColumn()) {
            throw new GenerateException("Header column required");
        }
        for (int column = 0; column < dataSource.getColumnCount(); column++) {
            String seriesName;
            if (dataSource.hasHeaderRow()) {
                seriesName = dataSource.getHeaderRowValue(column);
            } else {
                seriesName = "Series " + (column + 1);
            }
            TimeSeries series = new TimeSeries(seriesName, timePeriodClass);
            for (int row = 0; row < dataSource.getRowCount(); row++) {
                RegularTimePeriod period;
                try {
                    Date date = format.parse(dataSource.getHeaderColumnValue(row));
                    Constructor ctor = timePeriodClass.getConstructor(new Class[] { Date.class });
                    period = (RegularTimePeriod) ctor.newInstance(new Object[] { date });
                } catch (Exception e) {
                    throw new GenerateException(e);
                }
                series.add(period, dataSource.getCell(row, column));
            }
            dataset.addSeries(series);
        }
    } else if (dataSeries.equals("rows")) {
        if (!dataSource.hasHeaderRow()) {
            throw new GenerateException("Header row required");
        }
        for (int row = 0; row < dataSource.getRowCount(); row++) {
            String seriesName;
            if (dataSource.hasHeaderColumn()) {
                seriesName = dataSource.getHeaderColumnValue(row);
            } else {
                seriesName = "Series " + (row + 1);
            }
            TimeSeries series = new TimeSeries(seriesName, timePeriodClass);
            for (int column = 0; column < dataSource.getColumnCount(); column++) {
                RegularTimePeriod period;
                try {
                    Date date = format.parse(dataSource.getHeaderRowValue(column));
                    Constructor ctor = timePeriodClass.getConstructor(new Class[] { Date.class });
                    period = (RegularTimePeriod) ctor.newInstance(new Object[] { date });
                } catch (Exception e) {
                    throw new GenerateException(e);
                }
                series.add(period, dataSource.getCell(row, column));
            }
            dataset.addSeries(series);
        }
    } else {
        throw new GenerateException("Invalid series parameter:" + dataSeries);
    }
    return dataset;
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) Constructor(java.lang.reflect.Constructor) GenerateException(com.xpn.xwiki.plugin.charts.exceptions.GenerateException) Date(java.util.Date) GenerateException(com.xpn.xwiki.plugin.charts.exceptions.GenerateException) DataSourceException(com.xpn.xwiki.plugin.charts.exceptions.DataSourceException) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) RegularTimePeriod(org.jfree.data.time.RegularTimePeriod) SimpleDateFormat(java.text.SimpleDateFormat)

Example 40 with TimeSeries

use of org.jfree.data.time.TimeSeries in project MtgDesktopCompanion by nicho92.

the class HistoryPricesPanel method refresh.

private void refresh() {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    TimeSeries series1 = new TimeSeries(title);
    if (showAll) {
        for (MTGDashBoard d : MTGControler.getInstance().getDashBoards()) {
            TimeSeries series = new TimeSeries(d.getName());
            Map<Date, Double> mapTime;
            try {
                mapTime = d.getPriceVariation(mc, me);
                if (mapTime != null) {
                    for (Entry<Date, Double> da : mapTime.entrySet()) series.add(new Day(da.getKey()), da.getValue().doubleValue());
                    dataset.addSeries(series);
                }
            } catch (IOException e) {
                MTGLogger.printStackTrace(e);
            }
        }
    } else {
        for (Entry<Date, Double> d : map.entrySet()) series1.add(new Day(d.getKey()), d.getValue().doubleValue());
        dataset.addSeries(series1);
    }
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Price Variation", "Date", "Price", dataset, true, true, false);
    if (showEdition)
        try {
            for (MagicEdition edition : MTGControler.getInstance().getEnabledProviders().loadEditions()) {
                Date d = new SimpleDateFormat("yyyy-MM-dd hh:mm").parse(edition.getReleaseDate() + " 00:00");
                TimeSeriesDataItem item = series1.getDataItem(new Day(d));
                if (item != null) {
                    double x = item.getPeriod().getFirstMillisecond();
                    double y = item.getValue().doubleValue();
                    XYTextAnnotation annot = new XYTextAnnotation(edition.getId(), x, y);
                    annot.setToolTipText(edition.getSet());
                    XYPlot plot = (XYPlot) chart.getPlot();
                    plot.addAnnotation(annot);
                }
            }
        } catch (Exception e) {
            MTGLogger.printStackTrace(e);
        }
    pane.setChart(chart);
    pane.addMouseWheelListener(mwe -> {
        if (mwe.getWheelRotation() > 0) {
            pane.zoomOutDomain(0.5, 0.5);
        } else if (mwe.getWheelRotation() < 0) {
            pane.zoomInDomain(1.5, 1.5);
        }
    });
    this.add(pane, BorderLayout.CENTER);
    chart.fireChartChanged();
}
Also used : TimeSeries(org.jfree.data.time.TimeSeries) MTGDashBoard(org.magic.api.interfaces.MTGDashBoard) MagicEdition(org.magic.api.beans.MagicEdition) TimeSeriesDataItem(org.jfree.data.time.TimeSeriesDataItem) IOException(java.io.IOException) Date(java.util.Date) JFreeChart(org.jfree.chart.JFreeChart) IOException(java.io.IOException) XYTextAnnotation(org.jfree.chart.annotations.XYTextAnnotation) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) Day(org.jfree.data.time.Day) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

TimeSeries (org.jfree.data.time.TimeSeries)53 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)37 XYPlot (org.jfree.chart.plot.XYPlot)11 Date (java.util.Date)10 JFreeChart (org.jfree.chart.JFreeChart)10 Month (org.jfree.data.time.Month)9 TimeSeriesDataItem (org.jfree.data.time.TimeSeriesDataItem)8 BasicStroke (java.awt.BasicStroke)7 Color (java.awt.Color)7 Map (java.util.Map)7 Day (org.jfree.data.time.Day)6 RegularTimePeriod (org.jfree.data.time.RegularTimePeriod)6 IOException (java.io.IOException)5 List (java.util.List)5 DateAxis (org.jfree.chart.axis.DateAxis)5 NumberAxis (org.jfree.chart.axis.NumberAxis)5 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)5 FixedMillisecond (org.jfree.data.time.FixedMillisecond)5 BufferedImage (java.awt.image.BufferedImage)4 SimpleDateFormat (java.text.SimpleDateFormat)4