MDL-84398 libraries: Configure locale property for ChartJs

ChartJs has a property called locale that makes possible to format scale
numbers according to a language. This way we ensure that decimal places
will be displayed correctly in the chart labels and tooltips.
This commit is contained in:
Pedro Jordao
2025-02-27 21:37:36 -03:00
parent 269d534310
commit 81df76169b
3 changed files with 5 additions and 3 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+3 -1
View File
@@ -200,6 +200,7 @@ define([
datasets: this._makeDatasetsConfig()
},
options: {
locale: document.documentElement.getAttribute('lang'),
responsive: true,
maintainAspectRatio: false,
plugins: {
@@ -307,10 +308,11 @@ define([
Output.prototype._makeTooltip = function(tooltipItem) {
// Get series and chart data to rebuild the tooltip and add labels.
const formatter = new Intl.NumberFormat(this._config.options.locale);
var series = this._chart.getSeries()[tooltipItem.datasetIndex];
var serieLabel = series.getLabel();
var chartData = tooltipItem.dataset.data;
var tooltipData = chartData[tooltipItem.dataIndex];
var tooltipData = formatter.format(chartData[tooltipItem.dataIndex]);
// Build default tooltip.
var tooltip = [];