JfreeChart XYAreaChart draw shape at each point

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
anand.nevase
Posts: 2
Joined: Wed Apr 15, 2015 2:53 pm
antibot: No, of course not.

JfreeChart XYAreaChart draw shape at each point

Post by anand.nevase » Wed Apr 15, 2015 3:30 pm

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

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: JfreeChart XYAreaChart draw shape at each point

Post by paradoxoff » Thu Apr 16, 2015 11:58 am

Have you used XYAreaRenderer.AREA_AND_SHAPES as style in the construction of your renderer?

anand.nevase
Posts: 2
Joined: Wed Apr 15, 2015 2:53 pm
antibot: No, of course not.

Re: JfreeChart XYAreaChart draw shape at each point

Post by anand.nevase » Thu Apr 16, 2015 1:53 pm

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

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: JfreeChart XYAreaChart draw shape at each point

Post by John Matthews » Thu Apr 16, 2015 4:26 pm

Cross-posted here; a suggested approach is shown here.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: JfreeChart XYAreaChart draw shape at each point

Post by paradoxoff » Thu Apr 16, 2015 5:46 pm

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:

Code: Select all

class FillingStroke implements Stroke{
    public Shape createStrokedShape( Shape shape ){
        return 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.

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: JfreeChart XYAreaChart draw shape at each point

Post by John Matthews » Fri Apr 17, 2015 5:16 pm

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.

Locked