TimeSeries JFreeChart中的XYPointerAnnotation

时间:2013-08-12 12:02:05

标签: java jfreechart

我正在尝试将XYPointerAnnotation实施到TimeSeries图表。但是我不知道,图表如何找到我的y值来绘制。代码:

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);

如何解析TimeSeriesXYPointerAnnotation的y值?

1 个答案:

答案 0 :(得分:2)

给定TimeSeries

TimeSeries series = new TimeSeries("Data");

找到感兴趣的项目,

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

根据期间和值创建注释

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

并将其添加到图中,

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

enter image description here