score:2

Accepted answer

after a long struggle and research, i came up with below solution.

it will give me _datasetindex which is helpful to understand the click event triggered from prime and fibonacci or my second dataset line. if activepoints[0]._datasetindex is 0 then it's from prime and fibonacci, similarly if activepoints[0]._datasetindex is 1 then it's from my second dataset.

ctx.onclick = function(evt) {
    var activepoints = linechart.getelementsatevent(evt);

    if (activepoints.length) {
      var mouse_position = chart.helpers.getrelativeposition(evt, linechart.chart);

      activepoints = $.grep(activepoints, function(activepoint, index) {
        var leftx = activepoint._model.x - 5,
            rightx = activepoint._model.x + 5,
            topy = activepoint._model.y + 5,
            bottomy = activepoint._model.y - 5;

        return mouse_position.x >= leftx && mouse_position.x <=rightx && mouse_position.y >= bottomy && mouse_position.y <= topy;
      });
      console.log(activepoints[0]._datasetindex);
    }    
};

that said, here is working example jsbin. i believe this is going to help many people who is having same scenario/problem.


Related Query

More Query from same tag