XYPointerAnnotation in TimeSeries JFreeChart

强颜欢笑 提交于 2019-12-11 02:15:11

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/18186466/xypointerannotation-in-timeseries-jfreechart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!