score:31
Solution for ChartJs Version > 2.1.5:
Chart.pluginService.register({
beforeRender: function (chart) {
if (chart.config.options.showAllTooltips) {
// create an array of tooltips
// we can't use the chart tooltip because there is only one tooltip per chart
chart.pluginTooltips = [];
chart.config.data.datasets.forEach(function (dataset, i) {
chart.getDatasetMeta(i).data.forEach(function (sector, j) {
chart.pluginTooltips.push(new Chart.Tooltip({
_chart: chart.chart,
_chartInstance: chart,
_data: chart.data,
_options: chart.options.tooltips,
_active: [sector]
}, chart));
});
});
// turn off normal tooltips
chart.options.tooltips.enabled = false;
}
},
afterDraw: function (chart, easing) {
if (chart.config.options.showAllTooltips) {
// we don't want the permanent tooltips to animate, so don't do anything till the animation runs atleast once
if (!chart.allTooltipsOnce) {
if (easing !== 1)
return;
chart.allTooltipsOnce = true;
}
// turn on tooltips
chart.options.tooltips.enabled = true;
Chart.helpers.each(chart.pluginTooltips, function (tooltip) {
tooltip.initialize();
tooltip.update();
// we don't actually need this since we are not animating tooltips
tooltip.pivot();
tooltip.transition(easing).draw();
});
chart.options.tooltips.enabled = false;
}
}
});
score:0
If you got here because you were looking for a way to make pie charts always look hovered like I was. here is the solution that helped me: https://nobal.in/technology/chart-js/how-to-highlight-selected-in-pie-doughnut/
I just needed a way to programmatically enlarge one part of the pie chart, and this is exactly it
score:2
According to the closed issue on the github page for chart.js, displaying tool tips permanently is not recommended.
This comment closing this issue gives more detail:
https://github.com/chartjs/Chart.js/issues/1861#issuecomment-442852768
and this is the recommended plugin for permanent data labels:
score:15
I was looking for similar solution and came across this chartjs plugin Chart.PieceLabel.js. It has configs to display modes like label, value and percentage.
score:19
With the new Chart.js 2.1 you can write a plugin to do this and control it via an options
property
Preview
Script
Note that you need to register the plugin before you initialize the chart
Chart.pluginService.register({
beforeRender: function (chart) {
if (chart.config.options.showAllTooltips) {
// create an array of tooltips
// we can't use the chart tooltip because there is only one tooltip per chart
chart.pluginTooltips = [];
chart.config.data.datasets.forEach(function (dataset, i) {
chart.getDatasetMeta(i).data.forEach(function (sector, j) {
chart.pluginTooltips.push(new Chart.Tooltip({
_chart: chart.chart,
_chartInstance: chart,
_data: chart.data,
_options: chart.options,
_active: [sector]
}, chart));
});
});
// turn off normal tooltips
chart.options.tooltips.enabled = false;
}
},
afterDraw: function (chart, easing) {
if (chart.config.options.showAllTooltips) {
// we don't want the permanent tooltips to animate, so don't do anything till the animation runs atleast once
if (!chart.allTooltipsOnce) {
if (easing !== 1)
return;
chart.allTooltipsOnce = true;
}
// turn on tooltips
chart.options.tooltips.enabled = true;
Chart.helpers.each(chart.pluginTooltips, function (tooltip) {
tooltip.initialize();
tooltip.update();
// we don't actually need this since we are not animating tooltips
tooltip.pivot();
tooltip.transition(easing).draw();
});
chart.options.tooltips.enabled = false;
}
}
});
and then
new Chart(ctx, {
type: 'pie',
data: data,
options: {
showAllTooltips: true
...
With the older 2.x version, you should able to move the same (or similar, I'm not sure about the earlier data structure ) to the options.animation.onComplete
Fiddle - http://jsfiddle.net/q15ta78q/
Source: stackoverflow.com
Related Query
- Chart.js v2: How to make tooltips always appear on pie chart?
- Chart.js v2: How to make tooltips always appear on line chart?
- Chart JS, ng2-Charts - How to make the label to the right of pie chart instead on top?
- How to make chartjs pie chart responsive
- how to make scrollable the legends of pie chart ( chart js )
- how to add Thousand separator in pie chart tooltips of charts.js
- How do I make a pie chart showing number of people in an age group with JSON and ChartJS?
- How to make the size of pie chart fixed without using canvas (chart.js)
- How to make pie chart from array values?
- How can I make two of my lines in Chart JS thicker
- How set color family to pie chart in chart.js
- How can I make a stepline or stepped chart in chart.js or D3?
- Make pie chart smaller Chart JS
- How to display data labels outside in pie chart with lines in ionic
- How to hide section in a Chart.js Pie Chart
- How to create single value Doughnut or Pie chart using Chart.js?
- how to make a chart.js bar chart scrollable
- how to programmatically make a line chart point active/highlighted
- How do you set pie chart colors in angular-chart.js
- How to show tooltips always on Chart.js 2
- How to make Chart JS responsive?
- How to make bar chart animation where all bars grow at the same speed?
- How to make a chart scroll horizontally (when using Chart.js)
- How can I make line on chart thinner?
- ChartJs - Pie Chart - how to remove labels that are on the pie chart
- How to make sure tooltips never disappear on hover
- How can I rotate a pie chart in charts.js?
- How to show percentage (%) using chartjs-plugin-labels ( Pie chart ) in angular 2/8
- My pie chart (chartJs) does not appear
- ChartJS version 3 how to add percentage to pie chart tooltip
More Query from same tag
- Limit chart.js X axis ticks
- Chart.js time scale showing one of the dates wrong
- Chart.js - Scale of secondary y-axis?
- ChartJS: Show all tooltips with Total for Multi Pie chart
- ChartJS vertical bar chart - measure percentage of the data in each column based on a specified max
- chart.js remove lower grid from mixed chart
- How to position yAxes labels in chartJS
- Side effects from Chartjs for only *some* clients
- ChartJS adding shadow color to grid and custom x-axis labels
- How to allow zooming in between range only in chartjs-plugin-zoom
- Chart.js lost its colors
- how to show data label on barchart using chart.js in Angular10 project?
- Is there a way to let Chart.js to round up decimals?
- Chartjs Stacked bar have a stack id per x value
- ./~/chartjs-plugin-zoom/dist/chartjs-plugin-zoom.esm.js Module not found: Can't resolve 'chart.js/helpers'
- Make labels of ChartJS radar in a few rows
- Uncaught Error: [$injector:modulerr] Error: [$injector:nomod] Module 'chart.js' is not available
- Chartjs not showing up in Foundation5 Tabs
- charts.js data doesn't fit second y-axis
- Chart.js Chart Formatting - Legend & Y Axis & Title
- Can I specify a different font size for each row of text in Chart Title?
- Chart.js responsive option - Chart not filling container
- chartkick chart.js change colour of axis and colour of axis title
- how can i remove the grid lines in chartJs
- Change X and Y axis font color
- Chart.js line chart with area range
- Disable display of x and y values on ChartJS
- Add dynamically function to Chart.js
- Adding caret/arrow to a Chart.js custom html tooltip
- How to open a new Tab with javascript and display some chart