Tuesday, May 21, 2013

Jfreechart - Draw Custom Line

Draw Line at specific point (Vertical or Horizontal)

/***
* draw line at a specific value
* @param position
*/
public void drawLine(double position){
 // position is the value on the axis
 ValueMarker marker = new ValueMarker(position);  
 marker.setPaint(Color.black);
 
        // change line style (dashboard)
 BasicStroke dashedStroke = new BasicStroke(
               1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                1.0f, new float[] {6.0f, 6.0f}, 0.0f);
  
 marker.setStroke(dashedStroke);
 XYPlot plot = (XYPlot) chart.getPlot();
 
 //draw vertical line 
 plot.addDomainMarker(marker);
 
 //draw horizontal line 
 plot.addRangeMarker(marker)
}
 
 

0 comments:

Post a Comment