XYBlockRenderer Won't remove series

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
miladirooni
Posts: 24
Joined: Fri Sep 04, 2009 10:28 am
antibot: No, of course not.

XYBlockRenderer Won't remove series

Post by miladirooni » Thu Jul 29, 2010 1:04 pm

Hi

I have created a chart which uses XYBlockRenerer which looks like this:
Image

And I have list of check box with each series name next to it however when i uncheck a check box using this code

Code: Select all

   XYBlockRenderer renderer =(XYBlockRenderer) inFocus.getXYPlot().getRenderer();
   renderer.setSeriesVisible(0, Boolean.FALSE);
Nothing happens!!
Dose anyone have any idea on how to remove series from XYZDataset ?

and one more thing as u c in the image my data wont fit the plot area there is white gap between y axis and my series. im using these codes but wont work?

Code: Select all

        NumberAxis xAxis = new NumberAxis("X");
        xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        xAxis.setLowerMargin(4.0);
        xAxis.setUpperMargin(0.0);

        NumberAxis yAxis = new NumberAxis("Y");
        yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        yAxis.setLowerMargin(0.0);
        yAxis.setUpperMargin(0.0);
Cheers

miladirooni
Posts: 24
Joined: Fri Sep 04, 2009 10:28 am
antibot: No, of course not.

Re: XYBlockRenderer Won't remove series

Post by miladirooni » Fri Jul 30, 2010 3:47 pm

ANyone PlEaSe?

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

Re: XYBlockRenderer Won't remove series

Post by paradoxoff » Fri Jul 30, 2010 6:42 pm

The XYBlockRenderer does not care about the seriesVisible flag.
Try to insert the following code at the beginning of XYBlockRenderer.drawItem()

Code: Select all

if (!getItemVisible(series, item)) {
    return;
}
Concerning the "white gap":
You have probably created it yourself by calling

Code: Select all

xAxis.setLowerMargin(4.0);
You tell the axis to first calculate the range which is required to show all the data, and then reduce the lower bound by 400 % of the axis range. Since the default value of the autoRangeStickyZero flag is true, it is checked wether zero is larger than this reduced lower bound, and if so, zero is returned.
To solve that, call

Code: Select all

xAxis.setLowerMargin(0.0);
xAxis.setAutoRangeStickyZero(false);
That should reduce the displayed range of the number axis strictly to what is required to show all the data.

miladirooni
Posts: 24
Joined: Fri Sep 04, 2009 10:28 am
antibot: No, of course not.

Re: XYBlockRenderer Won't remove series

Post by miladirooni » Mon Aug 02, 2010 9:29 am

Hi Paradoxoff, thank you very much for the replay you first solution works like a charm if only one series is plotted in the chart if more that one dataset its in the chart then I get null pointer exeption

Code: Select all

   
                     if (!item.isSelected()) {
                        xYplot.getRenderer(index).setSeriesVisible(0, Boolean.FALSE);
                    }
.
It seems it dosen't have getRenderer(int i) method any Idea?
The second solution seems to have no effect on the chart at all

Code: Select all

        NumberAxis xAxis = new NumberAxis("X");
        xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        xAxis.setLowerMargin(0.0);
        xAxis.setUpperMargin(0.0);
        xAxis.setAutoRangeStickyZero(false);


        NumberAxis yAxis = new NumberAxis("Y");
        yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        yAxis.setLowerMargin(0.0);
        yAxis.setUpperMargin(0.0);
        yAxis.setAutoRangeStickyZero(false);
I still have gap between y axis and my plot.
I tried this bit of code

Code: Select all

  xYPlot.getDomainAxis().setRange(3.0, 170.0);
it works but when I zoom in and zoom out it goes back to the original (with a gap).
any Idea how to set range some how so that it doesn't goes back to the orignal plot.
Cheers

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

Re: XYBlockRenderer Won't remove series

Post by paradoxoff » Thu Aug 05, 2010 8:41 pm

Code: Select all

xAxis.setAutoRangeIncludesZero(false);

miladirooni
Posts: 24
Joined: Fri Sep 04, 2009 10:28 am
antibot: No, of course not.

Re: XYBlockRenderer Won't remove series

Post by miladirooni » Thu Aug 05, 2010 8:59 pm

Tanx

Locked