Home Forums Chart Support Y-Axis Minimum,Maximum and Interval Manual Plotting Reply To: Y-Axis Minimum,Maximum and Interval Manual Plotting



Axis minimum & maximum are auto-calculated based on the range of data being passed to the chart – which you can access using get method after rendering the chart. Or you can manually set minimum & maximum using set method. However, to set minimum / maximum of axis to the lowest / highest values of the datapoints passed, you can do so as addressed in the previous reply. Please find the code-snippet below.

var minY = Infinity, maxY = -Infinity;
var minimum = chart.axisX[0].get("minimum");
var maximum = chart.axisX[0].get("maximum");
for(var i = 0; i < chart.data[0].dataPoints.length; i++){
  if(chart.data[0].dataPoints[i].x >= minimum && chart.data[0].dataPoints[i].x <= maximum){
    if(chart.data[0].dataPoints[i].y < minY)
      minY = chart.data[0].dataPoints[i].y;

    if(chart.data[0].dataPoints[i].y > maxY)
      maxY = chart.data[0].dataPoints[i].y;
chart.axisY[0].set("minimum", minY);
chart.axisY[0].set("maximum", maxY);

Vishwas R
Team CanvasJS