JfreeChart LineAndShapeRenderer,如何为线条设置OutlinePaint?

JfreeChart LineAndShapeRenderer, How to setOutlinePaint for Line?

我在将 OutlinePaint 设置为来自 JFreeChart 中的 LineAndShapeRenderer 的线条时遇到问题。

我发现这篇文章 http://www.jfree.org/phpBB2/viewtopic.php?f=3&t=28347&p=78648&hilit=outlines+2d+line#p78648 也描述了我的问题。

David.Gilbert 写道 "You'll have to modify the LineAndShapeRenderer code, because right now it just draws a single line between the data points (using the seriesPaint)." 这是在 2009 年,我找不到任何今天的解决方案。

有没有人知道如何修改 LineAndShapeRenderer 来设置线条的轮廓。

谢谢大家

您必须覆盖 drawItem() method of LineAndShapeRenderer. In your implementation, you'll need to recapitulate the existing code, using the public accessors, as shown for XYLineAndShapeRenderer. The existing implementation uses the graphics context's fill() method to render a shape and draw() to stoke its outline; each invocation can have a different paint setting. No similar dichotomy exists for draw(line), but you can get a comparable effect using a composite Stroke, as shown here

I don't know how to set each paint.

从这个例子开始,draw() 一个 Line2D 有一种颜色和默认值 Stroke:

Line2D shape = new Line2D.Double(PAD, PAD, SIZE - PAD, SIZE - PAD);
g.setColor(Color.blue);
g.draw(shape);

draw() 另一种颜色的轮廓和 CompositeStroke:

BasicStroke s1 = new BasicStroke(16f);
BasicStroke s2 = new BasicStroke(1f);
g.setStroke(new CompositeStroke(s1, s2));
g.setColor(Color.red);
g.draw(shape);

另请参阅此相关 example