JFreeChart - change SeriesStroke of chart lines from solid to dashed in one line

Posted by MisterMichaelK on Stack Overflow See other posts from Stack Overflow or by MisterMichaelK
Published on 2012-11-05T21:09:06Z Indexed on 2012/11/06 17:00 UTC
Read the original article Hit count: 472

The answer accepted here (JFreechart(Java) - How to draw lines that is partially dashed lines and partially solid lines?) helped me start down the path of changing my seriesstroke lines on my chart. After stepping through my code and watching the changes, I see that my seriesstroke does in fact change to "dashedStroke" when it is supposed to (after a certain date "dai"), but when the chart is rendered the entire series line is dashed. How can I get a series line to be drawn solid at first and dashed after a set date?

/* series line modifications */
    final Number dashedAfter = timeNowDate.getTime();
    final int dai = Integer.parseInt(ndf.format(timeNowDate));

    XYLineAndShapeRenderer render = new XYLineAndShapeRenderer() {
      Stroke regularStroke = new BasicStroke();
      Stroke dashedStroke = new BasicStroke(
                                1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                                1.0f, new float[] {10.0f, 6.0f}, 0.0f );
      @Override
      public Stroke getItemStroke(int row, int column) {
        Number xVal = cd.getXValue(row, column);
        int xiv = xVal.intValue();
        if (xVal.doubleValue() > dashedAfter.doubleValue()) { 
          return dashedStroke; 
        } else { 
          return regularStroke; 
        }
      }

    };
    plot.setRenderer(render);

© Stack Overflow or respective owner

Related posts about java

Related posts about charts