How to draw line over a JFreeChart chart?

christo picture christo · Feb 9, 2012 · Viewed 14.4k times · Source

I have updatable OHLCChart. I need to draw a line over chart.

How to implement it?

Answer

Baldrick picture Baldrick · Feb 9, 2012

If you want to draw a vertical or horizontal line at a given position on an axis, you can use a ValueMarker :

ValueMarker marker = new ValueMarker(position);  // position is the value on the axis
marker.setPaint(Color.black);
//marker.setLabel("here"); // see JavaDoc for labels, colors, strokes

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

Use plot.addRangeMarker() if you want to draw an horizontal line.