AbelHeinsbroek / chartjs-plugin-crosshair

Crosshair plugin for ChartJS
https://chartjs-plugin-crosshair.netlify.com/samples/
MIT License
150 stars 86 forks source link

How to update zoomed graph datapoints if dataset is is shifted in x axis ? #129

Open NiTRoeSE opened 9 months ago

NiTRoeSE commented 9 months ago

Hi, first of all thanks for your work on this plugin! Is there any way to update the zoomed area to reload the datapoints ?

I have following problem: I have 2 wattage graphs from fit files in 1 canvas. Sometimes the recordings are slightly time shifted, so i implemented the possibility to shift the x axis timestamps to be able to move the graphs to match them.

The moving is implemented through manipulation of actual data ( the timestamps are epoch in milliseconds):

 data.map((element) => {
        element["x"] =  element["x"] - 1000
        return element["x"]["y"];
      });
chart.update();

The shifting works fine and graphs gets updated but when the graph moves no additional datapoints where loaded. So is there any way to call something like chart.crosshair.update(); to tell the plugin to reload the datapoints for the selected time range ?

Here a video wich shows the problem: ( If i zoom out and in again after shifting, all datapoints are present but not if i shift zoomed in)

https://github.com/AbelHeinsbroek/chartjs-plugin-crosshair/assets/24574743/2eeee4a4-3244-4414-b026-97b870049254

I tried to find something in code of plugin, but i´m not a js developer and didn't understand it well. Some help would be great, thanks in advanced !