score:8
Accepted answer
I've solved my problem using this awesome answer:
Click events on Pie Charts in Chart.js
The code:
$(document).ready(function() {
var canvas = document.getElementById("myChart");
var ctx = canvas.getContext("2d");
var myNewChart = new Chart(ctx, {
type: 'pie',
data: data
});
canvas.onclick = function(evt) {
var activePoints = myNewChart.getElementsAtEvent(evt);
if (activePoints[0]) {
var chartData = activePoints[0]['_chart'].config.data;
var idx = activePoints[0]['_index'];
var label = chartData.labels[idx];
var value = chartData.datasets[0].data[idx];
var color = chartData.datasets[0].backgroundColor[idx]; //Or any other data you wish to take from the clicked slice
alert(label + ' ' + value + ' ' + color); //Or any other function you want to execute. I sent the data to the server, and used the response i got from the server to create a new chart in a Bootstrap modal.
}
};
});
That works perfectly. Just instead of alerting the information, i send it to the server using AJAX, and displaying a new chart in a bootstrap modal.
Source: stackoverflow.com
Related Query
- How to drill down charts with ChartJS?
- how to get React chartjs to resize back down with window
- Chartjs drill down issue with multiple Y-Axis Bar/Line graph
- How can I load multiple Chartjs charts with different data on the same page?
- How to modify bar width in Chartjs 2 bar charts
- Chartjs linechart with only one point - how to center
- How to fix chart Legends width-height with overflow scroll in ChartJS
- ChartJS - Donut charts with multiple rings
- Add zoom event handler to charts for chartjs with chartjs-plugin-zoom
- How to customize Title position with ChartJS
- How to work out Chartjs using TypeScript with Chartjs.definitelyTyped from github
- How do I make line charts overlay over bar charts in chartjs
- How to create dynamic charts with Django and Chart.js?
- How to add ChartJS code in Html2Pdf to view image
- ChartJS - how to display line chart with single element as a line? (not as a dot)
- How to Change the Label Strike-Through with light gray on a ChartJS Doughnut?
- How to remove bars for those bars with zero value in Chartjs bar chart?
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- How to achieve the best possible performance with mutable data and real-time charts in React?
- How to create a simple Gauge with ChartJS v3?
- How to create chartjs chart with data from database C#
- How to use an Addon with ChartJS on Angular 4
- How to change ChartJS font size with javascript?
- how to set color for each item in tooltip with ChartJS
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- chartjs - how to set the order in which the different charts are displayed
- Chart.js - Draw charts with opposite bars - How to set both the y-axis ends to positive number?
- How do I correctly include Moment.js and Chart.js with RequireJS when I want to create charts with time scales?
- Chartjs 3.x - How to duplicate X axis on both sides of horizontal bar chart with only 1 dataset?
- how to highlight bar in ChartJS with onkeyup Input
More Query from same tag
- Hide or show two datasets with one click event of legend in chart.js
- How to generate bubble chart (Chart.js) using data from database FILTERED by user in Django?
- How to generate colors for unknown number of datasets in Chartjs
- Remove label from line chart - react-chartjs-2
- Chartjs does not show on pdf in yii2 despite showing in html view
- Having trouble fetching data from database for chart in ASP .NET Core
- How can I trigger the hover mode from outside the chart with charts.js 2?
- How do I selecting a date range (like onClick but drag/select)
- Why is pan (and zoom) not working on my Chart.js graph?
- How do I make the Line in ChartJS not exceed the maximum of yAxes
- How do you add custom text to tooltips in charts.js
- Chart.js - cannot read property
- ChartJS: Horizontal Bar with multiple datasets not showing Bars
- Angular 6 multiple dynamic Charts.js not showing
- Chart.js LineChart how to show only part of dataset and support horizontal scrolling
- chart.js aspect ratio not square
- Using chart.js in HotTowel , Angular.js
- How to dynamically change point location with line in Chart.js?
- ChartJS hover tooltip colors not showing their correct color
- How to change HTML style in ChartOption with if condition?
- Hide Chart.js bubble points based on filtering
- ChartJS line chart or bar graph from a Java program
- vue-chart.js / vuex: Chart not updating when vuex state changes
- Chartjs Stacked bar have a stack id per x value
- Refresh chart.config.data
- Can I make a horizontal bar chart with two category axes?
- ChartJS dynamic line chart ghosting back to old data when hovered on
- ChartJS - tooltip of one element is covering point that user should be able to select
- Charts.js How to add a link when you click a barchart?
- Blazor ChartJs: Expanding bar to the end of the canvas