Add individual shapes to a series using XYLineShapeRenderer

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
gsingh
Posts: 5
Joined: Mon Aug 20, 2018 10:34 am
antibot: No, of course not.

Add individual shapes to a series using XYLineShapeRenderer

Post by gsingh » Mon Aug 20, 2018 10:44 am

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?

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

Re: Add individual shapes to a series using XYLineShapeRenderer

Post by John Matthews » Mon Aug 20, 2018 6:29 pm

Yes. Override the renderer's getItemShape() method. A typical example may be found here.

gsingh
Posts: 5
Joined: Mon Aug 20, 2018 10:34 am
antibot: No, of course not.

Re: Add individual shapes to a series using XYLineShapeRenderer

Post by gsingh » Thu Aug 30, 2018 2:28 pm

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.

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

Re: Add individual shapes to a series using XYLineShapeRenderer

Post by John Matthews » Fri Aug 31, 2018 6:04 pm

Add a ChartMouseListener; examine the ChartEntity subclass to determine which point(s) should return a different shape from your implementation of getItemShape().

gsingh
Posts: 5
Joined: Mon Aug 20, 2018 10:34 am
antibot: No, of course not.

Re: Add individual shapes to a series using XYLineShapeRenderer

Post by gsingh » Tue Sep 11, 2018 2:14 pm

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.

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

Re: Add individual shapes to a series using XYLineShapeRenderer

Post by John Matthews » Wed Sep 12, 2018 3:03 am

Try returning an empty shape for the undesired points, e.g. ShapeUtilities.createUpTriangle(0).

Locked