本文介绍了DynamicTimeSeriesCollection中的XYTextAnnotation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在DynamicTimeSeriesCollection中实现XYTextAnnotation。
我不知道如何在DynamicTimeSeriesCollection中找到系列的X值。到目前为止我的代码:
I'm trying to implement XYTextAnnotation in DynamicTimeSeriesCollection.I have no idea how to find X value of series in DynamicTimeSeriesCollection. My code so far:
DynamicTimeSeriesCollection dataset = new DynamicTimeSeriesCollection(1, 60, new Minute());
final JFreeChart result = ChartFactory.createTimeSeriesChart(TITLE, "A", "B", dataset, true, true, false);
float[] series1Small = new float[10];
dataset.setTimeBase(new Minute(1, 1, 1, 1, 2013));
dataset.addSeries(series1Small,0,"1");
JFreeChart result = ChartFactory.createTimeSeriesChart(TITLE, "Время", "Платежи", dataset, true, true, false);
final XYPlot plot = result.getXYPlot();
-----------------------------------------------------------Below line doesn't work.
TimeSeriesDataItem item1 = series1.getDataItem(series1.getItemCount() - 1);
createAnnotation(item1,plot);
这是一个用于使用TimeSeriesCollection进行注释的函数。
This is a function that used to work for annotation with TimeSeriesCollection.
public static void createAnnotation(TimeSeriesDataItem item,XYPlot plot)
{
double xAnnotation = item.getPeriod().getFirstMillisecond();
double yAnnotation = item.getValue().doubleValue();
XYTextAnnotation annotation = new XYTextAnnotation(item.getValue().toString(), xAnnotation, yAnnotation);
annotation.setFont(new Font("Arial",Font.BOLD,11));
plot.addAnnotation(annotation);
}
推荐答案
从,我在 createChart()
中添加了以下行,以获取下面的图片:
Starting form this example, I added the following lines in createChart()
to obtain the image below:
double x = dataset.getXValue(0, COUNT - 1);
double y = dataset.getYValue(0, COUNT - 1);
String s = dataset.getY(0, COUNT - 1).toString();
XYTextAnnotation a = new XYTextAnnotation(s, x, y);
a.setFont(a.getFont().deriveFont(24f));
plot.addAnnotation(a);
这篇关于DynamicTimeSeriesCollection中的XYTextAnnotation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!