2

我正在尝试实现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);

如何将 y 值从 解析TimeSeriesXYPointerAnnotation

4

1 回答 1

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

在此处输入图像描述

于 2013-08-12T19:05:22.910 回答