1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| /**
* JFreeChart1.0.19 /orge/jfree/data/general/DatasetUtilities.findYValue
* Modify: to take in count the logarithmic xAxis: PA le 17/09/15
* ======
* Returns the interpolated value of y that corresponds to the specified
* x-value in the given series. If the x-value falls outside the range of
* x-values for the dataset, this method returns <code>Double.NaN</code>.
*
* @param dataset the dataset (<code>null</code> not permitted).
* @param series the series index.
* @param x the x-value.
* @param xlog true => xAxis in log, false => xAxis linear
* @return The y value.
*
* @since not in 1.0.19
*/
public static double findYValue(XYDataset dataset, int series, double x, boolean xlog) {
// delegate null check on dataset
int[] indices = DatasetUtilities.findItemIndicesForX(dataset, series, x);
if (indices[0] == -1) {
return Double.NaN;
}
if (indices[0] == indices[1]) {
return dataset.getYValue(series, indices[0]);
}
double x0 = dataset.getXValue(series, indices[0]);
double x1 = dataset.getXValue(series, indices[1]);
double y0 = dataset.getYValue(series, indices[0]);
double y1 = dataset.getYValue(series, indices[1]);
//Mod
if(xlog)
{//logarithmic xAxis
return y0 + (y1 - y0) * (Math.log10(x) - Math.log10(x0)) / (Math.log10(x1) - Math.log10(x0));
}else
{//linear xAxis
return y0 + (y1 - y0) * (x - x0) / (x1 - x0);
}
//EndMod
} |
Partager