Hi,
I have designed a Line chart using JFreeChart which has multiple series.
I am aware that you can add a shape to each data point on a plot using the XYLineAndShapeRenderer, but I was wondering if there is a way of adding shapes to individual data points on the plot.
My chart loads a new series from the data set when a checkbox on a separate panel is checked. I have tried adding annotations, but when I uncheck the checkbox (hence removing the plot from the chart) the annotations remain, and in any case, the annotations never seem to be added directly onto the plot.
Is it possible to use the XYLineAndShapeRenderer, or any type of renderer, to add these shapes on specific, predefined datapoints?
Add individual shapes to a series using XYLineShapeRenderer
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Add individual shapes to a series using XYLineShapeRenderer
Yes. Override the renderer's getItemShape() method. A typical example may be found here.
Re: Add individual shapes to a series using XYLineShapeRenderer
Hi, thank you for the reply, but I dont think this is quite what I'm looking for. I want to be able to add a shape to a specific point that the user clicks on on the line chart.
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Add individual shapes to a series using XYLineShapeRenderer
Add a ChartMouseListener; examine the ChartEntity subclass to determine which point(s) should return a different shape from your implementation of getItemShape().
Re: Add individual shapes to a series using XYLineShapeRenderer
The problem I am having with this approach is that I have a line chart, which I want without shapes at all the data points, except for the one defined by the mouse click. Doing this adds series shapes to each data point as well as the point defined by the mouse click.
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Add individual shapes to a series using XYLineShapeRenderer
Try returning an empty shape for the undesired points, e.g. ShapeUtilities.createUpTriangle(0).