Search code examples
highchartsangular2-highcharts

Get Id after addpoint in highchart


is there a way to get a callback in addpoint in highchart?

const coord = {x: event.xAxis[0].value, y: event.yAxis[0].value, title: 'Note', content: '', action: 'create' }

this.chart.series[2].addPoint( coord, true)

After I create the marker point, I can click on the marker and get the id, but i can't get the id immediately after I create it? Is there a way to do a call back on on addpoint?


Solution

  • This is a known issue and actually quite complex. Check this thread in Highcharts github with details why this functionality is not implemented so far: https://github.com/highcharts/highcharts/issues/10413.

    However, you can get the point reference from points array after the point is added:

      chart: {
        events: {
          load: function() {
            const chart = this,
                index = chart.series[1].points.length;
    
            chart.series[1].addPoint(400);
    
            let point = chart.series[1].points[index];
            console.log(point);
          }
        }
      }
    

    Demo: