I have a multiline chart drawn using chart.js. I want to get borderColor of the clicked point(datapoint) only, when the user clicks on a particular point.
For understanding, I have two lines in my multi-line chart called Prime and Fibonacci
and My Second dataset
drawn using dataset [12, 13, 15, 17, 111, 113, 117, 9, 3, 0]
and [2, 3, 5, 7, 11, 13, 17, 13, 21, 34]
respectively, both lines have a different borderColor green
and red
respectively.
Now, I want to catch only clicked point's borderColor
when the user clicks on the datapoints. For example, when the user clicks on datapoint 111
which is from line Prime and Fibonacci
then I should get borderColor as green
, similarly when the user clicks on datapoint 11
from My Second dataset
line, then I should get border color as red.
I have tried using below but it gives me both colors doesn't matter on which lines data point the user clicked.
var activePoints = lineChart.getElementsAtEvent(evt);
// Below code always gives me green and red, doesn't matter which line's data point the user clicked
activePoints[0]._chart.config.data.datasets[0].borderColor // Always gives green
activePoints[0]._chart.config.data.datasets[1].borderColor // Always gives red
How can I do that? For quick setup take help of jsbin.
Thanks in Advance!