score:1

sorry for the old code i didn't see the documentation may be you can find more userfull in the doc, i did on old school mode :).

position based on client with height :

canvas.onclick = function(evt){
    alert(evt.pagex, evt.pagey)
};

position based on charts :

var config = {}; //different (data, datasets, tooltips ...)
var ctx = document.getelementbyid("canvas").getcontext("2d");
var charts= new chart.scatter(ctx, config);
canvas.onclick = function(evt){
  var activepoints = charts.getelementsatevent(evt);
  var firstpoint = activepoints[0];
  if(firstpoint !== undefined){
    var label = charts.data.labels[firstpoint._index];
    var value = charts.data.datasets[firstpoint._datasetindex].data[firstpoint._index];

    alert(label + ": " + value.x);
    alert(label + ": " + value.y);
  }
};

taken from there :) click events on pie charts in chart.js thanks for him. regards.

score:6

for future readers, a workable solution:

chartclicked(event){
    var ytop = this.chart.chartarea.top;
    var ybottom = this.chart.chartarea.bottom;

    var ymin = this.chart.scales['y-axis-0'].min;
    var ymax = this.chart.scales['y-axis-0'].max;
    var newy = 0;

    if (event.offsety <= ybottom && event.offsety >= ytop) {
        newy = math.abs((event.offsety - ytop) / (ybottom - ytop));
        newy = (newy - 1) * -1;
        newy = newy * (math.abs(ymax - ymin)) + ymin;
    };

    var xtop = this.chart.chartarea.left;
    var xbottom = this.chart.chartarea.right;
    var xmin = this.chart.scales['x-axis-0'].min;
    var xmax = this.chart.scales['x-axis-0'].max;
    var newx = 0;

    if (event.offsetx <= xbottom && event.offsetx >= xtop) {
        newx = math.abs((event.offsetx - xtop) / (xbottom - xtop));
        newx = newx * (math.abs(xmax - xmin)) + xmin;
    };

    console.log(newx, newy);
};

credit to chart.js 2.0 current mouse coordinates tooltip


Related Query

More Query from same tag