score:10
this can be achieved using the following tooltips label callback function :
tooltips: {
mode: 'label',
callbacks: {
label: function(t, d) {
var dstlabel = d.datasets[t.datasetindex].label;
var ylabel = t.ylabel;
return dstlabel + ': ' + ylabel + ' €';
}
}
}
fyi: this has nothing to do with scales
. it would work perfectly fine along with scales
ᴡᴏʀᴋɪɴɢ ᴇxᴀᴍᴘʟᴇ ⧩
var mychart = new chart(ctx, {
type: 'bar',
data: {
labels: ['jan', 'feb', 'mar', 'apr', 'may'],
datasets: [{
label: 'dst1',
backgroundcolor: '#3e95cd',
data: [3, 2, 4, 5, 1]
}, {
label: 'dst2',
backgroundcolor: '#8e5ea2',
data: [2, 4, 1, 2, 5]
}]
},
options: {
scales: {
yaxes: [{
ticks: {
beginatzero: true,
stepsize: 1
}
}]
},
title: {
display: true,
text: 'title'
},
tooltips: {
mode: 'label',
callbacks: {
label: function(t, d) {
var dstlabel = d.datasets[t.datasetindex].label;
var ylabel = t.ylabel;
return dstlabel + ': ' + ylabel + ' €';
}
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.7.1/chart.js"></script>
<canvas id="ctx"></canvas>
score:2
a bit late to the party, but i have recently discovered javascript's built-in formatter for currencies, that saves you having to play about with strings and could be helpful here, and is reusable elsewhere in your code!:
const gbp = new intl.numberformat('en-gb', {
style: 'currency',
currency: 'gbp',
minimumfractiondigits: 2
});
being english i have of course done it in gbp, but i found that changing the en-gb
to de-de
and the 'gbp'
to 'eur'
worked absolutely fine. even formatting the decimal points and thousand separators correctly.
edit: including how to actually give the formatter a number to format would be useful wouldn't it!
gbp.format(10000); // returns £10,000.00
Source: stackoverflow.com
Related Query
- ChartJS add tooltip to a grouped bar chart
- ChartJS add custom tooltip to a stacked bar chart
- chartjs add dots to bars in grouped bar chart
- ChartJS version 3 how to add percentage to pie chart tooltip
- Grouped Bar Chart from mySQL database using ChartJS and PHP
- Grouped Bar Chart ChartJS
- Set fixed label size for grouped bar chart in angular Chartjs
- ChartJS - Horizontal Stacked Bar Chart Tooltip being cut off by Bottom of Canvas
- Using ChartJS to create a multiple grouped bar chart - see picture below
- Bar chart is not grouped properly in chartjs
- Chartjs Bar Chart add background color to value labels
- Add a click event to the bar chart of chartjs
- How to add vertical line in bar chart using chartJs and ng2-charts?
- Chartjs Bar Chart showing old data when hovering
- Chartjs v2.0: stacked bar chart
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- How to modify chartjs tooltip so i can add customized strings in tooltips
- Changing fontFamily on ChartJS bar chart
- chartjs : how to set custom scale in bar chart
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- Chartjs Bar Chart Legend
- show label in tooltip but not in x axis for chartjs line chart
- Add DataSet Bar Chart - Chart.JS
- Click event on stacked bar chart - ChartJs
- How to add second Y-axis for Bar and Line chart in Chart.js?
- Hide empty bars in Grouped Stacked Bar Chart - chart.js
- Chart.js - Add gradient to bar chart
- ChartJS bar chart with legend which corresponds to each bar
- ChartJs bar chart - keep bars left instead of equally spread across the width
- Border radius for the bar chart in ChartJS
More Query from same tag
- How to make chart with chartjs.?
- Chart Js, Style some ticks on the axis differently
- Only first value added gets displayed in ng2-chart linechart
- Chart.js - Line Chart format data to Lacs/Crores
- How to make chart which has both positive and negative value, starts with 0 - x axis
- Y scaling relative to the max value in my ChartJS chart
- Plotting firebase data to ChartJS
- Chart.js what is the new syntax for extending?
- Chart.js Find intersection Point and Draw a Circle
- Add a label to a point of a bubble graph (Chart.js)
- Adding options to vue-chartjs seems not working
- Outputting multiple SQL queries in chart.js
- how to draw Line chart using chart.js and datalabels should be shown
- ChartJS is not rendered
- Chart JS — Conditional horizontal row background colours
- Line Chart is not setting backgroundColor when created dynamically Chart.js
- How to use forEach loop on my array to plot x and y variables on my chart (Chart.js)
- How to get dynamic popover element after inserted to DOM?
- Chart.js Point image on hover
- Chart.js - Toggle visibility of charts
- Chart JS distance between bar stacked
- Add data to line chart js dynamically with multiple lines
- Chart.js version 2.2.1 wont show chart
- how can i add value on bar in the charts in chart.js vs 3.x
- y-axis values are way to high
- how to change thickness of two doughnut charts in chartjs
- Chart.js sync legend toggle on multiple charts
- ChartJS tooltip issue
- Pie Chart using chart.js not showing up but bar charts are?
- Range at the end of the line chart