score:-2
You should try to put the %
outside the value block.
I use it like this:
tooltipTemplate: "<%= label %>: <%= value %>%",
score:0
Mac's answer is super close, but I had an issue when implementing it as:
return data['datasets'][0]['data'][tooltipItem['index']] + '%';
instead use tooltipItem['datasetIndex'] to allow the correct display to show on hover. Otherwise it will only show the first array values no matter what is hovered on. My implemented solution below:
return data['datasets'][tooltipItem['datasetIndex']]['data'][tooltipItem['index']] + '%';
score:3
Mentioned solutions did not work for me. It throws away default label handling (data.labels/dataset labels) and you must format string again. If you need only to add percentage sign, you can simply use default callback Chart.defaults.global.tooltips.callbacks.label
as doc says. So for v2.x it will be:
options: {
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
return Chart.defaults.global.tooltips.callbacks.label(tooltipItem, data) + '%';
}
}
}
}
score:16
If you're using Chart.js 2.0 as suggested by @xnakos in the comments you have to use options.tooltips.callbacks.label
var dmgchartt = document.getElementById("dmgchart");
new Chart(dmgchartt, {
type: 'radar',
data: data,
options: {
tooltips: {
mode: 'label',
callbacks: {
label: function(tooltipItem, data) {
return data['datasets'][0]['data'][tooltipItem['index']] + '%';
}
}
},
scale: {
ticks: {
beginAtZero: true
}
},
title: {
display: true,
text: 'Title'
}
}
});
Source: stackoverflow.com
Related Query
- chart.js Adding Percantage Sign on Tooltip
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- Chart JS custom tooltip option?
- chart.js scatter chart - displaying label specific to point in tooltip
- Adding trendlines to existing chart Chart.js
- show label in tooltip but not in x axis for chartjs line chart
- Chart.js doughnut chart tooltip size?
- ChartJS add tooltip to a grouped bar chart
- Chart JS Show HTML in Tooltip
- chart js tooltip how to control the data that show
- Chart.js, adding footer to chart
- Adding Chart.js line chart to Jinja2/Flask html page from JS file
- Chart js v2 tooltip callback line breaks
- How to disable Chart JS tooltip when there is no value?
- Chart.js tooltip hover customization for mixed chart
- Add all data in the tooltip of Chart JS
- ng2-charts customize data and whole html content of tooltip displayed when hovering on bar chart
- Adding a label to a doughnut chart in Chart.js shows all values in each chart
- Charts.js tooltip overlapping text on chart
- ChartJS: Show all labels of a mixed chart in the tooltip
- Chart.js line chart tooltip shows wrong label when line doesn't start at first label
- Adding custom text to Bar Chart label values using Chart.js
- Chartjs adding icon to tooltip and label
- Chart JS custom tooltip not showing
- Chartjs - Insert additional data into chart tooltip
- Add a text as tooltip for each point on a line chart
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- Chart.js tooltip at any point on the chart
- Tooltip flickering when hovered on chart
- ChartJS version 3 how to add percentage to pie chart tooltip
More Query from same tag
- Chart for Real time data with duplicate x axis
- How to stop chartjs zoom more than visible points?
- ChartJS display tooltip at maximum/minimum value
- automatic legend translation on chart.js
- My chart is not shown on browser screen using chart.js in meteor
- native element not defined when ngSwitch condition in canvas element
- Implementing range slider in Chart.js
- chart.js: Place tooltip for stacked bar charts on top of bar
- How to customize Title position with ChartJS
- ChartJS bar not showing up for simple data points
- Chart.js Version 3: how to set the different color for tick lines and gridlines
- Redraw Chart.js with PHP JSON
- How To Match Left and Right Tick Intervals with Chartjs
- Chart.js: Change lengend colors to array
- Chart.js multiple columns of data for the same label
- chart js stripline? like one from canvas
- Changing Dataset for a chart in angular 10
- Setting Chart.js Pie-Graph Options
- React ChartJS 2 : Get data on clicking the chart
- How to get dynamic popover element after inserted to DOM?
- Chart.js Fill line chart from another value than 0
- Chart.js: Set different options to datasets
- ChartJS TypeError: document.getElementById(...).getContext is not a function
- Grouping by month with series of epoch timestamps in Chart.js
- How to update ChartJS in a long polling & stop animation stuttering?
- why is the background black when with Chartjs export to a image
- How to underline and bold tooltip chart js
- How to wait for data in useEffect hook before displaying it?
- Creating dynamic arrays in Angular2
- How to set a global chart.js tooltip label callback