我用标记解决了这个问题。下面是解决方法的代码:
JFreeChart chart = ChartFactory.createTimeSeriesChart(...);
XYPlot plot = chart.getXYPlot();
Long timestampToMark = new Date().getTime();
Marker m = new ValueMarker(timestampToMark);
m.setStroke(new BasicStroke(2));
m.setPaint(Color.RED);
plot.addDomainMarker(m);
我刚刚在最后一个域值上设置了自定义十字线:
XYPlot plot = chart.getXYPlot();
plot.setDomainCrosshairVisible(true);
plot.setDomainCrosshairPaint(Color.red);
plot.setDomainCrosshairStroke(new BasicStroke(3f));
plot.setDomainCrosshairValue(dataset.getXValue(0, dataset.getItemCount(0) - 1));