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开发者_StackOverflow社区 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?
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.
I'm going to risk being shot down in flames here because I'm an Android programmer without specific experience of AWT or JFreeChart, but I'll have a go.
Can you create your dashed line that alternates between two colours by superimposing two dashed lines, and offsetting the dash phase of one of them so that the dashes mesh together? I just looked at AWT's BasicStroke
class and I see that as well as specifying a dash array, you can specify the dash 'phase' as well.
Here's a potentially useful URL that shows how setting the phase affects the dashed stroke (near the bottom of the page): http://docstore.mik.ua/orelly/java-ent/jfc/ch04_05.htm
You might try a cyclic LinearGradientPaint
in conjunction with your BasicStroke
.
Addendum: To render sharp edges, consider java.awt.TexturePaint. To render orthogonal bondaries, consider java.awt.geom.Path2D.
精彩评论