Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

How could I take the position of points on line chart?

Open andr31 opened this issue 9 years ago • 2 comments

Does anyone know how to get the location of points on the canvas from the lineChart? I need to draw a line between 2 data points. And I want to use something like this: `ctx.beginPath();

ctx.moveTo(520, yValue); //from point A

ctx.lineTo(520, 90); // to point B`

In order to draw the line. Problem is, I need the position of each point A and point B on the canvas. and I don't know how to take them.

andr31 avatar Apr 14 '17 08:04 andr31

I think something like this will work:

var meta = chart.getDatasetMeta(datasetIndex);
var point = meta.data[index];
var x = point._view.x;
var y = point._view.y;

etimberg avatar Apr 14 '17 10:04 etimberg

@etimberg Thanks for your help and sorry for the late response. This solution solves my problem.

andr31 avatar Apr 26 '17 15:04 andr31