score:10
Redefine default global tooltip template as follows:
Chart.defaults.global.tooltipTemplate =
"<%if (label){%><%=label%>: <%}%><%= value %>";
Here is another example:
var ctx = document.getElementById("canvas").getContext("2d");
var myBarChart = new Chart(ctx).Bar(data, {
tooltipTemplate: "<%= value %> Files"
});
score:1
Drawing from other responses I've found that helped me, apparently the label properties can be set to functions, For example, to format currency:
var overrides = {
// show lables as currency
scaleLabel: toCurrency,
// String - Template string for single tooltips
tooltipTemplate: toCurrency,
// String - Template string for multiple tooltips
multiTooltipTemplate: toCurrency
}
function toCurrency(label) {
return '$' + label.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
score:1
The great previous answers do not work with chartjs 3. This example is from the official documentation:
const chart = new Chart(ctx, {
type: 'line',
data: data,
options: {
plugins: {
tooltip: {
callbacks: {
label: function(context) {
const label = context.dataset.label || '';
if (label) {
label += ': ';
}
if (context.parsed.y !== null) {
label += new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(context.parsed.y);
}
return label;
}}}}}});
score:23
Validated answer doesn't work anymore. For Chart.js V2,
Chart.defaults.global.tooltipTemplate
is deprecated.
Instead you can use callbacks to modify the displayed tooltips. There is a sample for the usage the possible callbacks in the documentation under Chart.defaults.global.tooltips.
In your case I would do the following:
window.myLine = new Chart(chart, {
type: 'bar',
data: barChartData,
options: {
tooltips: {
enabled: true,
mode: 'single',
callbacks: {
label: function(tooltipItems, data) {
return tooltipItems.yLabel + ' : ' + tooltipItems.xLabel + " Files";
}
}
},
}
});
Don't forget to set the HTML meta tag:
<meta charset="UTF-8">
This answer was copy from this question.
Source: stackoverflow.com
Related Query
- How to modify chartjs tooltip so i can add customized strings in tooltips
- How to modify chartjs tooltip to add customized attribute
- How to add ChartJS code in Html2Pdf to view image
- ChartJS version 3 how to add percentage to pie chart tooltip
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- How can I add a euro sign (€) to all tooltips in my chart js line chart
- How Can customize chartjs doughnut chart border and tooltip
- How can I add functionality to Chartjs Doughnut chart custom legend
- How to add dataset legend in chartjs tooltip
- How to disable a tooltip for a specific dataset in ChartJS
- How to add tooltips to chart.js graph
- How to modify bar width in Chartjs 2 bar charts
- ChartJS add tooltip to a grouped bar chart
- How can I hide tooltip in Chart.js on a specific data label?
- How to add label for ChartJs Legend
- How to change the color of legend in chartjs and be able to add one more legend?
- How can I force my ChartJS canvas legend to stay in a single column?
- How do you add custom text to tooltips in charts.js
- How can i add an image as background in Chartjs?
- How can I add some text in the middle of a half doughnut chart in Chart.JS?
- How to add background color between two lines in yAxis Chartjs
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- How can I create custom tooltips for each data point in a graph?
- Chartjs in Reactjs - how can I update data dynamically?
- How can I add an event to chart.js legend?
- how to set color for each item in tooltip with ChartJS
- How can I display different values on xAxes than on tooltip Chart.js V3
- How can I automatically wrap tooltip text content to multiple lines?
- How to add background color between two specific lines in Chartjs 3.1
- How can I load multiple Chartjs charts with different data on the same page?
More Query from same tag
- Chart js - render images on only one dataset
- How to use the useEffect function in react js chart 2 to change the labels?
- destroy method implementation in pie chart chartjs
- Deleting and recreating an element with React
- Chart JS version 3 not showing in pdf for engine wkhtmltopdf
- can't call any function inside of onClick function chart.js
- Chart.js not initiating
- Charts.js - Need to remove the data value from the Tooltip
- Chart.js Undesired Tooltip Showing Up for Legend
- Formatting axis labels using ChartsJS
- ChartJS - Line chart issue with only 1 point
- React - render Chart.js chart based on user selection, after Ajax returns JSON
- How to plot an equation using ChartJS?
- Bar values in Chart.js 2.X - dataset.metadata undefined
- ChartJS right Y-Axe ticks issue
- Chart.js - Setting x-axis based on user input
- is there a way to change the dispaly of a date
- Is it possible to change chartjs line value in one column ? No transition
- chartjs Line chart Javascript
- Chartjs does not show on pdf in yii2 despite showing in html view
- django 'LineChart' object has no attribute 'get'
- Chart.js Bar Chart change width (not duplicated to bar width questions!)
- Styling problems with Chart.Js
- Return List<object> from webservice
- In react.js with chart.js, I can't access to my data in a componant
- React-chartjs-2 update height dynamically
- chartjs chart spilling out of container
- ChartJS display tooltip at maximum/minimum value
- Chart.js: how to set multiple color to tick of y axes if > or < 0
- ChartJs bar chart - keep bars left instead of equally spread across the width