Home Forums Chart Support Find max peak on spline chart Reply To: Find max peak on spline chart

#37056

@dunhamcd,

We don’t have any property to find the coordinates of the highest / lowest peak as an inbuilt feature for now. However, with a few lines of code, it’s possible to find the same using canvas API, which we have showcased in the example shared in the previous reply. The same can be further improved to make it work across different sets of datapoints. Below is the code-snippet which gets the image-data of canvas to find the top-most colored pixel coordinate. Converting the same to value-coordinate using convertPixelToValue will give you the y-value of the highest peak in the curve/spline chart,

for (var i = 0; i < imageData.length; i += 4) {
  if (i % (4 * parseInt(chart1.plotArea.width)) === 0) {
    coloredRegionData.push([]);
    temp = i;
  }
  if (imageData[i] === 255 && imageData[i + 1] === 0)
    coloredRegionData[coloredRegionData.length - 1].push((i - temp) / 4);
}

Please take a look at this updated JSFiddle for complete code.

____
Adithya Menon
Team CanvasJS