[Chartjs]-Can I bind an onclick event and edit a point in chartjs

5👍

You can use the onclick event in the option to show the popup.
Then you can check whether a point was clicked with getElementsAtEvent and if so remove it from the options and update the chart.
I’ve updated your jsfiddle.

var option = {
    showLines: true,
    onClick: function(evt) {   
      var element = myLineChart.getElementAtEvent(evt);
      if(element.length > 0)
      {
        var ind = element[0]._index;
        if(confirm('Do you want to remove this point?')){
          data.datasets[0].data.splice(ind, 1);
          data.labels.splice(ind, 1);
          myLineChart.update(data);
        }
      }
    }
};

Leave a comment