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 “dashedAfter”), 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();
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);
if (xVal.doubleValue() > dashedAfter.doubleValue()) {
return dashedStroke;
} else {
return regularStroke;
}
}
};
render.setBaseShapesVisible(false);
render.setBaseShapesFilled(true);
render.setDrawSeriesLineAsPath(true);
plot.setRenderer(render);
Have you tried implementing
AbstractRenderer#getItemStroke?In this example I’m using a dashed line for x > 4 for series 2:
Although this example is using and
XYSeriesand not dates you shold be able to modify it for you needs.Here is the full example