Reputation:
I have the following jquery code to add a chart.js bar chart:
var config = {
type: 'bar',
data: {
datasets: [{
{% for key, value in iva_saldo_totale_trimestrale.items %}
data: {{ value|safe }},
{% endfor %}
backgroundColor: 'blue',
label: 'IVA'
}],
I have tried to add € to my label, but the following code does not work. why?
yAxes: [{
ticks: {
callback: function(value, index, values) {
return '€' + value;
}
Upvotes: 0
Views: 955
Reputation: 579
In order to add custom label, you should attach a callback as below :
var chart = new Chart(ctx, {
type: 'line',
data: data,
options: {
scales: {
yAxes: [{
ticks: {
// Include a dollar sign in the ticks
callback: function(value, index, values) {
return '$' + value;
}
}
}]
}
}
});
Important thing to remember here is that, if the callback returns null
or undefined
, the associated grid line will be hidden
Upvotes: 1