Adding a static gridline to a JFreeChart time series chart

别等时光非礼了梦想. 提交于 2019-12-01 22:17:23

Well, I solved it using a marker. Here's the code that does it:

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

Maybe someone else will find this useful.

I'd just set a custom cross-hair on the last domain value:

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