I have a chart and I want to format the values on the left side to money format. The image is where I want to change. the chart
That's my code so far:
this.Chart = new Chart('kpi', {
type: 'bar',
data: {
labels: cat,
datasets: [
{
data: Value,
label: "Categorias",
backgroundColor: 'rgba(26, 179, 148, 0.4)',
borderColor: 'rgba(26, 179, 148, 1)',
borderWidth: 2
}
]
},
options: {
events: ['mousemove', 'click'],
},
hover: {
mode: "nearest",
},
scales: {
yAxes: [{
id: 'data',
type: 'linear',
ticks: {
beginAtZero: true
}
}]
},
title: {
display: true,
text: 'Categorias',
fontSize: 20,
fontColor: 'rgba(26, 179, 148, 1)',
fontStyle: 'normal'
},
tooltips: {
mode: "nearest",
callbacks: {
title: (item, data) => {
},
label: (item, data) => {
let index = item.index;
item.value = numeral(data.datasets[0].data[index]).format('$0,0.00');
return `${data.labels[index]}: ${item.value}`
}
}
}
}
});
I want to format with ".format('$0,0.00')" like on the label, or something like that, but I don't know how to format those values.
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;
}
}
}]
}
}
});
This is a sample code to format the y axis value from the documentation page of chartjs. You can use this callback to format your labels.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.