Chartjs-Graph of an equation animated javascript (crash game)

0👍

You can try setting the Y max value like this in your code to auto adjust Y axis scale.

beforeInit: function(chart) {
  var data = chart.config.data;
  let maxValue = 0;
  for (var i = 0; i < data.datasets.length; i++) {
    for (var j = 0; j < data.labels.length; j++) {
      var fct = data.datasets[i].function,
        x = data.labels[j],
        y = fct(x);
        if (maxValue < y) {
          maxValue = y;
        }
      data.datasets[i].data.push(y);
    }
  }
  chart.options.scales.y.max = maxValue;
}

Leave a comment