Removing Value Axes.

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
merlushatrash
Posts: 19
Joined: Mon Sep 26, 2011 4:48 pm
antibot: No, of course not.

Removing Value Axes.

Post by merlushatrash » Sun Oct 09, 2011 2:28 pm

Dear all.
I have question how to add and remove value axes to chart in any order.
I am trying to use following code:
if I am adding dataset number N
setDataset(N,dataset);
setRangeAxis(N,new NumberAxis());
mapDatasetToRangeAxes(N,N);
if I am removing dataset :

setRangeAxis(N,null);
setDataset(N,null);

It works fine until I am deleting dataset with index 0. It throws NullPointerException in drawCrosshair methods.
How to fix it?

merlushatrash
Posts: 19
Joined: Mon Sep 26, 2011 4:48 pm
antibot: No, of course not.

Re: Removing Value Axes.

Post by merlushatrash » Tue Oct 18, 2011 10:50 am

Does anyone knows the answer?

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

Re: Removing Value Axes.

Post by paradoxoff » Tue Oct 18, 2011 11:07 am

Though you haven´t specified the exat location of the error: the API documentation is quite obvious:
public XYPlot(XYDataset dataset,ValueAxis domainAxis,ValueAxis rangeAxis,XYItemRenderer renderer)
Creates a new plot with the specified dataset, axes and renderer. Any of the arguments can be null, but in that case you should take care to specify the value before using the plot (otherwise a NullPointerException may be thrown).
The same can also happen when you set these object to null after creation of the plot.
In short: make sure tha the primary datase, renderer, and domain/range axes are all non-null.
Whyh do you need to set the axes to null?

merlushatrash
Posts: 19
Joined: Mon Sep 26, 2011 4:48 pm
antibot: No, of course not.

Re: Removing Value Axes.

Post by merlushatrash » Thu Oct 27, 2011 9:00 am

I need to add,remove dynamically graphs to the jfreechart.
If I adding graph I adding new dataset, put new renderer, put new axis.
If i removing graph I make dataset,renderer,axis is null.
However this approach is not working when I removing dataset with index 0.

Locked