本文介绍了TimeSeries JFreeChart中的XYPointerAnnotation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将XYPointerAnnotation
实施为TimeSeries
图表.但是我不知道,图表如何找到要绘制的y值.代码:
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);
如何解析从TimeSeries
到XYPointerAnnotation
的y值?
推荐答案
给出TimeSeries
,
TimeSeries series = new TimeSeries("Data");
找到感兴趣的项目,
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);
并将其添加到绘图中,
XYPlot plot = (XYPlot) chart.getPlot();
plot.addAnnotation(a);
这篇关于TimeSeries JFreeChart中的XYPointerAnnotation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!