CrazyFisch
CrazyFisch

Reputation: 25

JfreeChart LineAndShapeRenderer, How to setOutlinePaint for Line?

I've got a problem with setting an OutlinePaint to a line from LineAndShapeRenderer in JFreeChart.

I've found this article http://www.jfree.org/phpBB2/viewtopic.php?f=3&t=28347&p=78648&hilit=outlines+2d+line#p78648 which describes my problem also.

David.Gilbert writes "You'll have to modify the LineAndShapeRenderer code, because right now it just draws a single line between the data points (using the seriesPaint)." This was in 2009 and I can't find any todays solutions.

Does anybody has an idea how to modify the LineAndShapeRenderer to set the Outline of the line.

Thank you guys.

Upvotes: 0

Views: 595

Answers (1)

trashgod
trashgod

Reputation: 205775

You'll have to override the drawItem() method of LineAndShapeRenderer. In your implementation, you'll need to recapitulate the existing code, using the public accessors, as shown here 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.

Starting form this example, draw() a Line2D with one color and the default Stroke:

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

And draw() the outline with another color and a CompositeStroke:

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

See also this related example.

image

Upvotes: 2

Related Questions