score:1

Accepted answer

For this particular use case:

  1. You can use the update instead of the setData feature.

Demo: https://jsfiddle.net/BlackLabel/1bjfh63c/

Code:

button1.addEventListener('click', function() {
    let x = Math.floor(Math.random() * (99)) + 1;
    let y = Math.floor(Math.random() * (99)) + 1;
  chart1.series[0].setData(
        [{
            y: x,
        name: 'Apple',
        color: null,
        id: 1,
      },
      {
            y: y,
        name: 'Peach',
        color: null,
        id: 2,
      }
    ], false, false, false);

  chart1.redraw();
})
  1. In setData set the updatePoints flag to false - that's why the error occurred.

demo: https://jsfiddle.net/BlackLabel/umo14be0/

API: https://api.highcharts.com/class-reference/Highcharts.Series#setData


Related Query

More Query from same tag