Angular |素| Chart.js |格式化标签中的数字
Angular | PrimeNG | Chart.js | Formatting number in label
我在 Angular 项目中使用了 PrimeNG + chart.js。
我想格式化“工具提示”中的数字。例如:当前是“12345.67”,我需要“12.345,67”。我该怎么做?
这些是我的部分代码。
<p-chart type="bar" [data]="chartData" [options]="chartsOptions"></p-chart>
chartsOptions = {
locale: 'it', // or 'de', 'fr', 'it_IT'... doesn't work
legend: {
display: false,
}
}
charData = {
locale: 'it_IT',
labels: ['label1', 'label2', ...],
datasets: [
{locale: 'it_IT', ... },
...
]
}
无论如何都行不通。
我该怎么办?
将以下部分放入您的选项对象
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
var label = data.datasets[tooltipItem.datasetIndex].label || '';
label = logic to transform label from old to new
return label;
}
}
}
它的文档:https://www.chartjs.org/docs/latest/configuration/tooltip.html#label-callback
我在 Angular 项目中使用了 PrimeNG + chart.js。 我想格式化“工具提示”中的数字。例如:当前是“12345.67”,我需要“12.345,67”。我该怎么做?
这些是我的部分代码。
<p-chart type="bar" [data]="chartData" [options]="chartsOptions"></p-chart>
chartsOptions = {
locale: 'it', // or 'de', 'fr', 'it_IT'... doesn't work
legend: {
display: false,
}
}
charData = {
locale: 'it_IT',
labels: ['label1', 'label2', ...],
datasets: [
{locale: 'it_IT', ... },
...
]
}
无论如何都行不通。
我该怎么办?
将以下部分放入您的选项对象
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
var label = data.datasets[tooltipItem.datasetIndex].label || '';
label = logic to transform label from old to new
return label;
}
}
}
它的文档:https://www.chartjs.org/docs/latest/configuration/tooltip.html#label-callback