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);
}
}
}
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();
}
}
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();
}
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;
}
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();
}
Aggregations