I want to draw shape (circle) at each XYPoint in XYAreaChart. Kindly suggest me how can i add shaped at each point.
I tried using following option but still not able to draw shape:
XYPlot plot = (XYPlot) chart.getPlot();
XYAreaRenderer renderer= (XYAreaRenderer)plot.getRenderer();
renderer.setOutline(true);
renderer.setSeriesItemLabelsVisible(0, true);
renderer.setSeriesItemLabelsVisible(1, true);
renderer.setSeriesShape(1, ShapeUtilities.createDiamond(.5f));
renderer.setSeriesShape(0, ShapeUtilities.createDiamond(.5f));
renderer.setBaseShape(ShapeUtilities.createDiamond(.5f));
renderer.setBaseSeriesVisible(true);
renderer.setSeriesOutlinePaint(0, Color.decode("#34C0F1"));
renderer.setSeriesOutlinePaint(1, Color.DARK_GRAY);
renderer.setSeriesPaint(1, Color.decode("#EBEBEB"));
renderer.setSeriesPaint(0, Color.decode("#B4DEED"));
Still unable to get result
JfreeChart XYAreaChart draw shape at each point
-
- Posts: 2
- Joined: Wed Apr 15, 2015 2:53 pm
- antibot: No, of course not.
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: JfreeChart XYAreaChart draw shape at each point
Have you used XYAreaRenderer.AREA_AND_SHAPES as style in the construction of your renderer?
-
- Posts: 2
- Joined: Wed Apr 15, 2015 2:53 pm
- antibot: No, of course not.
Re: JfreeChart XYAreaChart draw shape at each point
I am successfully added shape using XYAreaRenderer.AREA_AND_SHAPE. But shape is not Solid (not filled with colour), Please suggest me how can i add Solid shapes to XYPoints
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: JfreeChart XYAreaChart draw shape at each point
Does not look like a cross post to me. And the suggested approach won´t work since the type of renderer is different (here an XYAreaRenderer, in the other post, its an XYLineAndShapeRenderer).
A look in the source of XYAreaRenderer shows that even if it should draw Shapes, it just draws them and does not fill them. So overriding any of the getItemXYZ methods won´t work.
But you can do something very creative:
As suggested here, the call to g.draw( shape ) (where g is an instanceof Graphics2D) is effectively a call to g.fill( g.getStroke().getStrokedShape( shape )).
You can try to define your own Stroke that in its createStrokedShape( Shape shape ) Method, simply returns the original shape:
and then set this Stroke as seriesStroke in your renderer.
Note that you won´t see any outlines around your shape when you use this approach.
A look in the source of XYAreaRenderer shows that even if it should draw Shapes, it just draws them and does not fill them. So overriding any of the getItemXYZ methods won´t work.
But you can do something very creative:
As suggested here, the call to g.draw( shape ) (where g is an instanceof Graphics2D) is effectively a call to g.fill( g.getStroke().getStrokedShape( shape )).
You can try to define your own Stroke that in its createStrokedShape( Shape shape ) Method, simply returns the original shape:
Code: Select all
class FillingStroke implements Stroke{
public Shape createStrokedShape( Shape shape ){
return shape;
}
}
Note that you won´t see any outlines around your shape when you use this approach.
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: JfreeChart XYAreaChart draw shape at each point
I respectfully disagree about the cross-post; the code is verbatim, and the other site requires citation. I overlooked the XYAreaRenderer context; thank you for clarifying. I like the possibility of using createStrokedShape(); more on that here.