Apparently, we can get the min and max of x
values on the screen but can not get for the y
value directly. We should iterate every x
values to get max/min of y
between the screen interval. So my code is something like :
const { data } = chart.data.datasets[0];
var xMin = 0;
var xMax = data.length;
// I set yMin as yMax to get yMin while iterating over x values
var yMin = chart.scales.y.max;
var yMax = 0;
xMin = chart.scales.x.min;
xMax = chart.scales.x.max;
for (let i = xMin; i < xMax; i++) {
let y = data[i];
yMin = Math.min(y, yMin);
yMax = Math.max(y, yMax);
}
So I can get the min/max of y
between leftmost and rightmost pixels of the chart area.