chartjs / chartjs-plugin-zoom

Zoom and pan plugin for Chart.js
MIT License
598 stars 327 forks source link

Old method of getting zoomed in minIndex and maxIndex of visible points no longer works. #837

Closed twilson90 closed 2 weeks ago

twilson90 commented 1 month ago

I have a zoomable line chart and I need to know the visible dataset indices. According to old answers on stackoverflow chart.scales.x.minIndex and chart.scales.x.maxIndex were available in older versions, but they no longer appear to exist in the latest version of chartjs. I can get the value range with _range but I would need to process the entire dataset to find the indices from that, and my dataset is rather massive (which is why I'm using zoom)

gopal-panigrahi commented 1 month ago

@twilson90 Can you provide the relevant code with which you are having issue .

kurkle commented 2 weeks ago

Chart.js uses binary search internally to find the visible indices, but does not store them. See https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.extras.ts#L87