Tuesday, May 14, 2013

Jfreechart - Change line stye

This would make your second series show as a dashed line:
plot.getRenderer().setSeriesStroke(
    1, 
    new BasicStroke(
        2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
        1.0f, new float[] {6.0f, 6.0f}, 0.0f
    )
 

Override the getItemStroke() method in AbstractRenderer.
     final BasicStroke dashedStroke = new BasicStroke(
                  2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                  1.0f, new float[] {6.0f, 6.0f}, 0.0f);
     XYLineAndShapeRenderer render = new XYLineAndShapeRenderer() {
        @Override
        public Stroke getItemStroke(int row, int column) {
            if (column < dashedThreshold) {
                return lookupSeriesStroke(row);
            } else {
               return dashedStroke;
            }
       };
 
Reference:
http://stackoverflow.com/questions/7797353/jfreechartjava-how-to-draw-lines-that-is-partially-dashed-lines-and-partiall 

0 comments:

Post a Comment