How do cahnge the pallete used by a renderer?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
tedbyers
Posts: 50
Joined: Fri Oct 12, 2007 7:05 pm

How do cahnge the pallete used by a renderer?

Post by tedbyers » Thu Jun 04, 2009 6:00 pm

Actually, I have three questions.

The first is in the subject line. If I create a java.util.Vector<Color>, how can I use it to change the default pallete the renderer uses. I really don't care what colour is used for a given series. I just don't want certain colours used. For example, I have a custom renderer that uses precisely two colours, and I want to exclude those two colours from the pallete used by the default renderer (the default XY line and shape renderer in this case) used by the plot for the second dataset that has been added to the plot.

Second, how many colours are actually available in the default pallete? And was that pallete constructed to enable even those who are colour blind to distinguish between series?

Finally, is it possible to tell a renderer that two series that have been added to a given dataset ought to be displayed in the same colour (e.g. the upper and lower confidence interval for a mean). There is no a priori way to determine what statistics a user has asked to be plotted, so one can't know, going in, whether or not the confidence interval has been requested or what index will identify it in the dataset to be plotted. NB: I can live without a solution to this last query, at least for a time. But certainly ideas for a solution would be welcome.

Thanks

Ted

tedbyers
Posts: 50
Joined: Fri Oct 12, 2007 7:05 pm

Re: How do cahnge the pallete used by a renderer?

Post by tedbyers » Thu Jun 04, 2009 8:29 pm

Well, I found two logical places to handle this.

The first is the DefaultDrawingSupplier class, but it does not provide an interface for changing the pallete. Since a 'setPallete(java.awt.Paint[] v)' function isn't there, where is it. Or do I have to extend the DefaultDrawingSupplier class and the renderer classes to make use of the extended drawingsupplier (I have found the getDrawingSupplier function in the renderers, but no setDrawingSupplier)?

The second is the ChartColor class. Again, it would be trivial to extend it to have a function that returns a different pallete (but then, it is trivial for anyone familiar with awt to make a function that constructs any pallete one wishes). The problem is how to get a chart, ultimately through the renderer(s) it uses, to use whatever pallete one creates.

Any ideas?

Thanks,

Ted

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

Re: How do cahnge the pallete used by a renderer?

Post by paradoxoff » Fri Jun 05, 2009 7:26 am

The missing setter for the DrawingSupplier is located in the Plot class.
If you assign an XYItemRenderer to an XYPlot, the XYPlot calls renderer.setPlot(this) and sets the private plot variable in the AbstractXYItemRenderer class. AbstractXYItemRenderer.getDrawingSupplier() then returns plot.getDrawingSupplier().
In order to use a different "Palette", you can either construct a DefaultDrawingSupplier using the constructors that allow to set the different paint/stroke/shape sequences or extend DefaultDrawingSupplier or implement the DrawingSupplier interface.
The number of colors that are used is thus up to you. In order to determine whether the paints used by the DefaultDrawingSupplier (which is btw, the array returned by ChartColor.createDefaultPaintArray()) is readable for color-blind people, you could simply make the check if you know such a person. Personally, I didn´t like the default colors too much (most of them seemed to be a little greyish).
Finally, concerning your last question: there are a several possibilities to make a renderer handle "special series".
First, when the user asks some statistics to be plotted (I assume that this is done in some kind of GUI), you should be able to find out what renderer will be responsible to render the special series (i.e. in the method where the statistics are calculated, the series or dataset generated and added to the plot you should be able to get a reference to the renderer) and set the series shape/stroke/paint explicitly. These settings will be maintained if the "special statistics series" is replaced with an ordinary series unless you capture this "replacement" and set the series shape/stroke/paint back from "special" to "normal". Note that this can be achieved w/o subclassing the renderer.
Second option is to subclass the renderer, introduce some kind of "seriesSpecial" flag and override getSeriesPaint(int series) to check whether the series is "special" and if so, return a "special" shape/stroke/paint and if not, return super.getSeriesPaint(int series). This flag would also have to be set and reset in the method where the statictics are defined or replaced with a normal dataset.

Locked