Java 烛台图表上的注释不起作用

Java 烛台图表上的注释不起作用,java,jfreechart,Java,Jfreechart,我正在尝试向图表添加注释。它似乎被添加了,因为如果我再添加一个,绘图的注释列表的size()会增加。问题是它没有被显示出来 OHLCDataset candles = createCandleDataset(); // Create chart chart = ChartFactory.createCandlestickChart( "mychart", "", "", candles, true); XYPlot plot = (XYPlot) chart.getPlot();

我正在尝试向图表添加注释。它似乎被添加了,因为如果我再添加一个,绘图的注释列表的
size()
会增加。问题是它没有被显示出来

OHLCDataset candles = createCandleDataset();

// Create chart
chart = ChartFactory.createCandlestickChart(
    "mychart", "", "", candles, true);

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

XYShapeAnnotation a1 = new XYShapeAnnotation(
    new Rectangle2D.Double(10.0, 20.0, 20.0, 30.0),
    new BasicStroke(1.0f), Color.blue);
plot.addAnnotation(a1);

ChartPanel panel = new ChartPanel(chart);
setContentPane(panel);
有什么想法吗?

API上说:

形状坐标在数据空间中指定

相对于实际数据,
矩形2D
的坐标可能不明显。取而代之的是,使用来自的坐标来构造注释。下面的图表将重点放在
系列1
中的第二项上,说明如何从基础
OHLCSeries
中检索数据,以创建一个周期宽且跨越高/低值的注释

// series
addSeries1();
OHLCSeries series = seriesCollection.getSeries(0);
OHLCItem item = (OHLCItem) series.getDataItem(1);
RegularTimePeriod t = item.getPeriod();
long x = t.getFirstMillisecond();
long w = t.getLastMillisecond() - t.getFirstMillisecond(); 
double y = item.getLowValue();
double h = item.getHighValue() - y;
XYShapeAnnotation a1 = new XYShapeAnnotation(
    new Rectangle2D.Double(x, y, w, h),
    new BasicStroke(1f), Color.blue
);
chart.getXYPlot().addAnnotation(a1);


的其他实现具有相应的访问器。

好的,我假设坐标(0,0)将位于绘图的左上角。。。我会试试你的代码!哦,我明白了。。Y坐标为
价格
,X坐标为
毫秒
。因为我使用日线图,所以我的X值很大,比如说
3600*1000*24
@BakedInhalf:没错;我已经更新了片段以使用目标物品的句点。