Chart.js How to get min-max values of X axis?

2.3k Views Asked by At

How can I get the values ​​at both ends of the X axis?

I use chartjs-plugin-zoom to zoom and pan time-series data charts. I want to get the minimum and maximum values of x-axis ​​at that time.

zoom: {
    zoom: {
      enabled: true,
      mode: 'x',
      onZoom: function () {
         var min = myChart[i].getDatasetMeta(i).dataset._scale.chart.scales.x-axis-0.table[0].time;
         console.log('min', min);
      }
   }
}

I expected to get the value from this. But "x-axis-0" contains an operator.

What should I do?

1

There are 1 best solutions below

0
On

This is Ok, Maby

zoom: {
        zoom: {
            enabled: true,
                mode: 'x',
                    onZoom: function () {
                        var minVal = myChart[i].getDatasetMeta(i).dataset._scale.chart.scales['x-axis-0']._table[0].time;
                        var maxVal = myChart[i].getDatasetMeta(i).dataset._scale.chart.scales['x-axis-0']._table[1].time;
                        console.log('minVal', minVal);
                        console.log('minVal', minVal);
                    }
        }
    }