score:0
Accepted answer
you can do this by defining a tooltip label callback function as follows.
tooltips: {
callbacks: {
label: (tooltipitem, data) => {
var value = data.datasets[0].data[tooltipitem.index];
var total = data.datasets[0].data.reduce((a, b) => a + b, 0);
var pct = 100 / total * value;
var pctrounded = math.round(pct * 10) / 10;
return value + ' (' + pctrounded + '%)';
}
}
}
please have a look at below runnable code snippet.
new chart('empgender', {
type: 'doughnut',
data: {
labels: ['male', 'female'],
datasets: [{
backgroundcolor: ['#f56954', '#00a65a'],
bordercolor: ['rgba(255, 99, 132, 1)', 'rgba(54, 162, 235, 1)'],
data: [17, 7],
borderwidth: 1
}]
},
options: {
maintainaspectratio: true,
responsive: true,
cutoutpercentage: 80,
tooltips: {
callbacks: {
label: (tooltipitem, data) => {
var value = data.datasets[0].data[tooltipitem.index];
var total = data.datasets[0].data.reduce((a, b) => a + b, 0);
var pct = 100 / total * value;
var pctrounded = math.round(pct * 10) / 10;
return value + ' (' + pctrounded + '%)';
}
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.9.3/chart.min.js"></script>
<canvas id="empgender" height="100"></canvas>
Source: stackoverflow.com
Related Query
- Laravel - How to Display both count and percentage (%) in chartjs pie chart
- ChartJS version 3 how to add percentage to pie chart tooltip
- How to display chart using Chartjs with JSON data in Laravel
- how to display name on multi series pie chart in chartjs
- Chart.js How to sum the values in a pie chart and display them in the header
- How to use plugins in chartjs and laravel chart consoletvs/chartsjs
- ChartJS - How to add Text between Pie Chart and Legend
- Chartjs Line chart options display increase and decrease percentage between each datapoint
- chartjs datalabels change font and color of text displaying inside pie chart
- Display values outside of pie chart in chartjs
- How to display data labels outside in pie chart with lines in ionic
- How can I display the xAxes and yAxes data in the tooltip, Chart JS?
- ChartJS - how to display line chart with single element as a line? (not as a dot)
- ChartJs - Pie Chart - how to remove labels that are on the pie chart
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- How to show percentage (%) using chartjs-plugin-labels ( Pie chart ) in angular 2/8
- How to create a chart that uses strings for both the X and Y axes?
- ChartJS : How to display two "y axis" scales on a chart
- Chartjs 3.x - How to duplicate X axis on both sides of horizontal bar chart with only 1 dataset?
- how to display chart data as html table chartjs
- how to add percentage value to legend field in pie chart using chart.js
- how to display multiple sum with chart js and laravel?
- How to update a chart using VueJS and ChartJS
- How to style a pie chart in chart js? I want to change the border color, border width and give them shadow
- 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 can I change the cursor on pie chart segment hover in ChartJS 3?
- How to make chartjs pie chart responsive
- how to increase space between legend and chart in chartjs (ng2charts ) using angular
- How to get Data from API to display chart using chartjs in Vuejs
More Query from same tag
- ChartJS: line graph with labels on the y-axis
- JSON.parse label data from string var
- How to address type errors when removing data with chart.js?
- Chart js cut the title and the legends
- Chartjs v2 - format tooltip for multiple data sets (bar and line)
- Chart.js - Multiple JSON data object array [{x: Date, y: count}....] representing each dataset of the chart
- Chart.js - Can't hide PolarArea by using display:false
- Convert SQLite PHP array into Javascript array?
- HTML/Chart JS deserialize JSON from Python Flask
- How to remove excess lines on X axis using chartjs?
- Click on chart to expand more information - Chart.js
- Angular 2 - Invoking function from a JS file (chart.js) - function not found
- Chart.js data goes backwards when retroactively pushing datapoint from HTTP request using Angular
- how to use chartJS to show breakdown of selected data
- Django Chart.js
- chart.js renders outside div and canvas
- How to add background color between two lines in yAxis Chartjs
- How to convert a bar legend to line legend in chart.js 2.7.2?
- How to start Y Axis Line at 0 from right for negative values in chart js 2?
- Implementing ChartJs
- Dynamic Chart Data
- Decimal in x-axis
- Chart.js time scale showing one of the dates wrong
- pan on chart.js also zoom on line charts
- Two chartjs charts on page throwing data undefined error
- Using Chart.js on Laravel 5.3
- Remove label from line chart - react-chartjs-2
- padding not working in my chartjs line-graph
- X-axis multiple colored label for bar chart using chart.js
- Keep two Pie Charts Side by Side