javaawtjfreechart

How to create a dashed line that alternates between two colours?


I'm using JFreeChart and want to plot a series of data using a line that alternates between gray and black dashes, with no space between. i.e. grayblackgrayblackgrayblack

JFreeChart will only accept an AWT Stroke or Shape object as the method of rendering series.

As I understand it, a BasicStroke can only have one colour and alternate between opaque and transparent. Is there another class that implements Stroke that would allow multiple colours? Or is there another way to solve this problem?


Solution

  • I've had a similar issue with JFreeChart. I ended up simply extending the appropriate plot and overriding some of the draw methods. It's not an ideal solution but there is simply a limit on what you can do with JFreeChart.