Chartjs-Chartjs change values on resize

1👍

The problem is in your medians function. You are sorting the array, and so the chart is reacting to that. A simple thing to do would be to slice into a new array. I renamed the paramater to inValues and the set the original values = inValues.slice()

function median(inValues) {
  const values = inValues.slice();

  values.sort(function(a, b) {
    return a - b;
  });

  if (values.length === 0) return 0

  var half = Math.floor(values.length / 2);

  if (values.length % 2)
    return values[half];
  else
    return (values[half - 1] + values[half]) / 2.0;
}

Leave a comment