I created a line chart using the Chart.js library. My goal is to calculate the weighted sum when hovering over a specific data point, based on the difference between that point and its neighboring points. For instance, if point[0] = 5 with weight 2, point[1] = 10 with weight 3, and point[2] with weight 4, upon hovering on point[2], I would like to display a calculation like:
point[0]*2 + (point[1]-point[0])*3 + (point[2]-point[1])*4
Do you have any suggestions on how I can achieve this? I've been experimenting with loops and conditionals, but it doesn't seem to be the most efficient solution given the multiple indexes involved.