Renderer methods don't have expected effect.

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jahjeremy
Posts: 31
Joined: Tue Sep 25, 2012 2:49 am
antibot: No, of course not.

Renderer methods don't have expected effect.

Post by jahjeremy » Fri Sep 28, 2012 9:47 pm

It seems that calling the method Renderer.setBasePaint() and others like it doesn't have the effect I would expect.

For example, I would expect this to make all datasets drawn by this Renderer to have a color of blue:

Code: Select all

XYBarRenderer r = new XYBarRenderer();
r.setBasePaint(Color.blue);
But it doesn't. The datasets are drawn with the default color (red).

Instead, to make this work, one has to set the Paint for individual datasets:

Code: Select all

r.setSeriesPaint(0, Color.blue);
And that will drawn the 1st series as blue.

Is this working as intended? Shouldn't setting the "base" attributes like color on the Renderer cause it to use these as the default when rendering its dataset? Or am I missing something here? Is it "working as intended" that I always have to do this on a per-dataset basis? Or perhaps I can override this behavior with some kind of "use base" method?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Renderer methods don't have expected effect.

Post by david.gilbert » Sat Sep 29, 2012 6:24 am

The basePaint is a default value used for any series that doesn't have a seriesPaint specified. This can happen if you call setSeriesPaint(index, null), or if you call setAutoPopulateSeriesPaint(false) before first rendering your chart. The default configuration of the renderer will auto-populate everything so you have less work to do.

I don't recall for the XYBarRenderer if it uses the paint or fillPaint attributes to the color the bars (it is one or the other).
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

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

Re: Renderer methods don't have expected effect.

Post by jahjeremy » Wed Oct 03, 2012 7:23 pm

Hello, David. Thanks for the reply.

Here is what I tried to do initially for setting the default color of the bars:

Code: Select all

XYBarRenderer barRenderer = new XYBarRenderer();
barRenderer.setBasePaint(Color.blue);
barRenderer.setBaseFillPaint(Color.blue);
Then I set the renderer in the chart:

Code: Select all

chart.getXYPlot().setRenderer(1, barRenderer);
The bars are the second collection, so that's why I assign index = 1 for this renderer.

But it doesn't work. The bars are the default red color.

However, adding this one line fixes things:

Code: Select all

barRenderer.setSeriesPaint(0, Color.blue);
I guess this is explicitly assigning the renderer to the first series in the collection. (Or such is my understanding.)

I don't call either setSeriesPaint(index, null) or setAutoPopulateSeriesPaint(false) in my code, which you indicated could cause this behavior.

So it appears to me this isn't working quite correctly.

Or perhaps not and I am just misunderstanding how this is supposed to work. Any insight? Do you need the full demo code? I could probably do that if you needed it.

The dataset being used is an XYIntervalSeriesCollection with two XYIntervalSeries, if that matters.

strator
Posts: 1
Joined: Mon Nov 09, 2009 9:46 pm
antibot: No, of course not.

Re: Renderer methods don't have expected effect.

Post by strator » Thu Mar 21, 2013 3:59 pm

Hi,

this is a problem I'm struggeling right now, too. The problem is, that the first argument of setSeriesPaint (the int) is the index
of the series in an dataset. If you have multiple datasets with multiple series, than the first series of each dataset will have
the index one. The renderer looks up a Paint using the series index. That's why all your series have the same color (index 0 = red).

I did'nt find a way to have different colors for series in different datasets.

Bye
Torsten

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

Re: Renderer methods don't have expected effect.

Post by paradoxoff » Thu Mar 21, 2013 11:04 pm

Just in case somebody stumbles over this thread:
The basePaint will only take effect if the autopopulateSeries flag is set o false. Otherwise, the renderer will pick up a color from the drawing supplier.
jahjeremy wrote: I don't call either setSeriesPaint(index, null) or setAutoPopulateSeriesPaint(false) in my code, which you indicated could cause this behavior.
The point is that setAutoPopulateSeriesPaint(false) needs to be called explicitly. If not the renderer will pick up a series paint from the DrawingSupplier, and the basePaint will not be used.
strator wrote: I did'nt find a way to have different colors for series in different datasets.
Use two different renderers.
Normally, the n-th dataset is rendered by the n-the renderer. If no n-th renderer has been added to the plot, the renderer with index 0 will be used.

Locked