2

I'm trying to implement XYPointerAnnotation to TimeSeries chart. However I don't know, how does chart finds my y values to plot. Code:

final TimeSeries series = new TimeSeries("asdfas");
Hour hour = new Hour();
series.add(2,hour), 123);
TimeSeriesCollection collection = new TimeSeriesCollection();
collection.addSeries(series);
double temp = Double.parseDouble(
    series1.getTimePeriod(series1.getItemCount()-1).toString());
XYPointerAnnotation pointer1 = new XYPointerAnnotation(
    series1.getValue(series1.getItemCount() - 1).toString(), temp, 00.0);
JFreeChart chart = ChartFactory.createTimeSeriesChart(
    "1", "2", "3", collection, true, true, false);

How can I parse y values from TimeSeries to the XYPointerAnnotation?

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
max
  • 1,579
  • 1
  • 19
  • 34

1 Answers1

2

Given a TimeSeries,

TimeSeries series = new TimeSeries("Data");

find the item of interest,

TimeSeriesDataItem item = series.getDataItem(series.getItemCount() - 1);

create an annotation based on the period and value,

double x = item.getPeriod().getFirstMillisecond();
double y = item.getValue().doubleValue();
XYPointerAnnotation a = new XYPointerAnnotation("Bam!", x, y, 5 * Math.PI / 8);

and add it to the plot,

XYPlot plot = (XYPlot) chart.getPlot();
plot.addAnnotation(a);

enter image description here

trashgod
  • 203,806
  • 29
  • 246
  • 1,045