use of org.jfree.data.time.TimeSeriesDataItem in project qpid-broker-j by apache.
the class TimeSeriesBuilderCallbackTest method testAddPointToSeries.
@Test
public void testAddPointToSeries() {
TimeSeriesHolder timeSeriesHolder = new TimeSeriesHolder();
SeriesDefinition seriesDefinition = mock(SeriesDefinition.class);
when(seriesDefinition.getSeriesLegend()).thenReturn(SERIES_LEGEND);
timeSeriesHolder.beginSeries(seriesDefinition);
timeSeriesHolder.addDataPointToSeries(seriesDefinition, new SeriesRow(_dates[0], _values[0]));
timeSeriesHolder.addDataPointToSeries(seriesDefinition, new SeriesRow(_dates[1], _values[1]));
timeSeriesHolder.addDataPointToSeries(seriesDefinition, new SeriesRow(_dates[2], _values[2]));
timeSeriesHolder.endSeries(seriesDefinition);
TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) timeSeriesHolder.getPopulatedDataset();
TimeSeries actualTimeSeries = timeSeriesCollection.getSeries(SERIES_LEGEND);
for (int i = 0; i < NUMBER_OF_DATA_POINTS; i++) {
TimeSeriesDataItem dataItem0 = actualTimeSeries.getDataItem(i);
assertEquals(_dates[i].getTime(), dataItem0.getPeriod().getMiddleMillisecond());
assertEquals(_values[i], dataItem0.getValue());
}
}
use of org.jfree.data.time.TimeSeriesDataItem 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();
}
use of org.jfree.data.time.TimeSeriesDataItem in project pentaho-platform by pentaho.
the class TimeSeriesCollectionChartDefinition method setDataByRow.
private void setDataByRow(final IPentahoResultSet data) {
// TODO Make this routine MDX friendly
if (data == null) {
// $NON-NLS-1$
noDataMessage = Messages.getInstance().getString("CHART.USER_NO_DATA_AVAILABLE");
// No data so we've got nothing to set
return;
// TODO come up with some sort of error strategy here.
}
Class timePeriodClass = TimeSeriesCollectionChartDefinition.getTimePeriodClass(getDomainPeriodType());
Object[] rowData = data.next();
while (rowData != null) {
String seriesName = (String) rowData[0];
TimeSeries wrkSeries = new TimeSeries(seriesName, timePeriodClass);
for (int column = 1; column < rowData.length - 1; column = column + 2) {
Date keyDate = getValidDate(rowData[column]);
TimeSeriesDataItem timeSeriesDataItem = new TimeSeriesDataItem(RegularTimePeriod.createInstance(timePeriodClass, keyDate, RegularTimePeriod.DEFAULT_TIME_ZONE), ((Number) rowData[column + 1]).doubleValue());
wrkSeries.add(timeSeriesDataItem);
}
addSeries(wrkSeries);
rowData = data.next();
}
if ((data.getRowCount() > 0) && (this.getSeriesCount() <= 0)) {
// $NON-NLS-1$
noDataMessage = Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT");
}
}
Aggregations