StackedXYBarRenderer method setSeriesVisible does not work

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Paul Belleville
Posts: 15
Joined: Wed Nov 07, 2007 6:20 pm

StackedXYBarRenderer method setSeriesVisible does not work

Post by Paul Belleville » Wed Dec 24, 2008 11:41 pm

I am using jfreechart 1.0.9.

I am using the StackedXYBarRenderer and when I try to hide a series using the setSeriesVisible method, it does not work.
The legend item for the particular series gets hidden, but the series bars withing the graph do not disappear.

((StackedXYBarRenderer)((XYPlot) plot).getRenderer()).setSeriesVisible(i, false);

Let me know if you have seen this and if you have a solution.
Thanks
Paul B.

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

Post by paradoxoff » Sun Jan 04, 2009 10:26 pm

Not all renderers care about the flag(s) that determine whether an item or a series should be visible or not. The right place to perform this check is the start of the drawItem-method. The parameter list contains the series and the item index. One of the first lines in every renderer should be like the following:

Code: Select all

if (!getItemVisible(series, item) || !getSeriesVisible(series)) {
    return;
}
If you check the source code of the StackedXYBarRenderer class (i.e. the drawItem method) you will see that this check is indeed missing.
Solution: edit the source and recompile.

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Post by skunk » Sun Jan 04, 2009 11:14 pm

Don't forget that you will also need to add code that checks the series visibility flag when calculating the aggregate height of each stack

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

Post by david.gilbert » Mon Jan 05, 2009 9:54 pm

skunk wrote:Don't forget that you will also need to add code that checks the series visibility flag when calculating the aggregate height of each stack
This minor complication combined with my own laziness has led to the "series visible flag" being ignored by many of the bar renderers. It would be nice to have this working correctly.
David Gilbert
JFreeChart Project Leader

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

Locked