hi,
i want to retreive the y value for the corresponding x-value.
i used
public double getYValue(int series, int item),
a method of XYDataset.
when i used that method, Nullpointer exception is thrown.
i cant intialise XYDataset,because it is an interface.
my x-axis is date and i want the return type of the function as double.
is there any method to get the y-value for the corresponding x-value.
can anyone please help me to solve the above problem.
how toget the Y value for a particular x value in JFreeChart
First you'll have to get the correct XYDataset. Retrieve it from your plot:
Iterate over the dataset till you find the X value you're looking for, then save its position and retrieve the desired Y value based on X's position. Be aware that you can have more then one series.
Code: Select all
XYDataset dataset = chartPanel.getChart().getXYPlot().getDataset();
Code: Select all
int itemCount = dataset.getItemCount(0);
for (int k=0; k<itemCount; k++) {
if (dataset.getX(0,k) == <something>)
break;
}
double y = dataset.getYValue(0,k);