How to customize marker for a XYPlot

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
freephys
Posts: 1
Joined: Wed Dec 12, 2012 11:17 pm
antibot: No, of course not.

How to customize marker for a XYPlot

Post by freephys » Tue Jan 15, 2013 11:01 pm

Hi, jfree coder,

I am encountering a problem of customizing markers for a XYPlot. Simply speaking, I have several columns of data plotted as XYPlot. I know how to add marker to the plot with various marker to each column. However, since some data are too close to each other, therefore I am asked to remove marker for several column and keep markers for the rest in order to differentiate them.

Currently, all columns are read in one shot and I would like to keep it that way with the customization. If I do need to read them twice and how can I have xyplot painted twice?
Some code snippet would be appreciated if possible

Thanks
Happy new Year to all

jahjeremy
Posts: 31
Joined: Tue Sep 25, 2012 2:49 am
antibot: No, of course not.

Re: How to customize marker for a XYPlot

Post by jahjeremy » Tue Feb 12, 2013 3:31 am

I'm not sure if you figured this out. Post is kind of old.

Anyways, I would approach this problem by separating your data into multiple datasets according to what markers (or shapes) you want them to have on the plot and then assigning them the appropriate renderers.

You can set the shape drawn by the renderer with:

Code: Select all

XYItemRenderer.setSeriesShape(0, shape);
Or

Code: Select all

XYitemRenderer.setBaseShape(shape);
I can never get setBaseShape() to work like I expect so I tend to use the setSeriesShape(), setSeriesPaint(), etc. set of methods.

So, for instance, this is some pseudocode for putting two data sets with separate renderers onto the same XYPlot:

Code: Select all


// Set shapes on renderers
renderer1.setSeriesShape(0, shape1);
renderer2.setSeriesShape(0, shape2);

// Set renderer and data set on plot
xyplot.setDataset(0, dataset);
xyplot.setRenderer(0, renderer1);

// Set 2nd renderer and data set 
xyplot.setRenderer(1, renderer2);
xyplot.setDataset(1, dataset2);

etc.
The shapes are just AWT Shape objects.

Nice thing about JFreeChart is that you can have as many datasets and renderers as you need to draw your chart.

Locked