Last active
January 5, 2021 05:40
-
-
Save Braytiner/b08a767695efe1d22f94c2879cd33c78 to your computer and use it in GitHub Desktop.
Valores monetários PT-BR para chart.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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