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.
Source: stackoverflow.com
Related Query
- Chart.js 2.x - How to get handle of only clicked datapoint?
- How to display value of only one datapoint in line chart
- How to get clicked bar chart tooltip data?
- How to get item what been clicked on Chart (primeNg chart + angular application)
- ChartJs how to get from mulitiple dateset which dataset bar is clicked
- Angular chart.js onClick is not working - how to get all elements of a bar when it is clicked on
- How to get the actual chart width and height in chart.js
- How to access or get value of specific graph on chart plot by click event?
- How to get chart from data points (arrays) with inconsistent time intervals and chart.js?
- Chartjs 3.x - How to duplicate X axis on both sides of horizontal bar chart with only 1 dataset?
- Chart.js: How to get x-axis labels to show on top of bars in bar chart
- How do I get a chart.js chart to display data in a Node/React web application?
- Get Value for point clicked on Pie Chart in Chart.js 3
- how to determine which bar was clicked on a chart js
- How to get labels on ChartJS Pie chart segments
- How to reuse a Chartjs Chart component in with different Data and get past the **Canvas is already in use** error?
- How to get Data from API to display chart using chartjs in Vuejs
- How to get the data attribute of the canvas chart created using chartjs
- How do I get a different label for each bar in a bar chart in ChartJS?
- How to split data from api to get a chart
- How to get line x value from Label chart js
- How to show tooltip only when data available in chart js?
- How to get access to Chart instance related to current tooltip callback in Chart.js
- How to show/hide animation when legend clicked chart js
- How to print a chart rendered by code
- How can I get my Chart.JS bar chart to stack two data values together on each bar, and print a calculated value on each bar?
- How to See Only the Image of Chart
- How to get rid of the line on top of every point on a line chart (Chart.js)
- How to get the X position at a specified chart item index?
- React: How to get loading spinner to show whilst API data loads into my chart.js chart
More Query from same tag
- chart.js data wont update
- Trying to get multiple chart.js charts to load on the same page
- Is it possible to scale Chart.js background Image
- Adding image on chart js
- My chart.js canvas disappears after hide() function
- How to print multiple items with the same charts? any directions?
- Dotted lines using Chart.js
- syntax error, unexpected ' ' Laravel 5.6 ConsoleTvs chart js
- Why does one chart overlays another (chart.js)?
- Chart JS, Choose different Y-axis for different datasets
- How to inject data into chartjs plugin function?
- Allowing Chart.js to work with jQuery Tabs
- ChartJS Line chart causes browser crash
- How to put 2 labels and distinct tooltips from two bars
- web page doesn't display chart or any error
- How to add panning to chart in chartjs?
- How do i find area under the graph
- Change the Center color of doughnut chart in Chart.Js
- Can the colors of bars in a bar chart be varied based on their value?
- How to hide/show bars differentiate by a colors and by click on labels, using chartjs bar charts?
- int Array with empty value
- How to implement chart js using viewbag in mvc razor
- How to customize the title and tooltip in ux-chartjs?
- Integrate Blazor with Chart.js: how to pass an object
- How to change line color based on data - chartist or chart.js
- Chart with Time axis only displaying first grid line and tick label (unitStepSize)
- How to make customized stepSize for each horizontal bar in Chart.js graph
- Show labels on each sector to polar chart using angular js chart
- "<%=value%>" in javascript not ASP.net
- Chart.js 2.1.6: Drawing horizontal Limit Lines?