Skip to content

Instantly share code, notes, and snippets.

@Braytiner
Last active January 5, 2021 05:40
Show Gist options
  • Save Braytiner/b08a767695efe1d22f94c2879cd33c78 to your computer and use it in GitHub Desktop.
Save Braytiner/b08a767695efe1d22f94c2879cd33c78 to your computer and use it in GitHub Desktop.
Valores monetários PT-BR para chart.js
/*
Adding a ‘thousands’ separator to ChartJS’s Y axis and tooltips
I learned the toLocaleString() method for adding thousands separators from this Github issue (https://github.com/chartjs/Chart.js/issues/411)
These options in your options config will add a thousands separator to your tooltips and yAxes.
*/
options: {
tooltips: {
callbacks: {
label: function(tooltipItems, data) {
return data.labels[tooltipItems.index] + ": " + data.datasets[0].data[tooltipItems.index].toLocaleString();
/* Para gráficos do tipo radar
return "R$ " + data.datasets[tooltipItems.datasetIndex].data[tooltipItems.index].toLocaleString();
*/
}
}
},
scales: {
yAxes: [{
ticks: {
beginAtZero: false,
callback: function(value, index, values) {
return value.toLocaleString();
}
}
}]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment