Simone Sessa
Simone Sessa

Reputation: 873

Angular | PrimeNG | Chart.js | Formatting number in label

I used PrimeNG + chart.js in my Angular project. I would to format the number in the "tooltip". For example: currently it's "12345.67", I need "12.345,67". How can I do this?

These are parts of my code.

<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', ... },
        ...
    ]
}

In any case it doesn't work.
How can I do?

Upvotes: 2

Views: 1807

Answers (1)

LeeLenalee
LeeLenalee

Reputation: 31411

Place the following part in your options object

tooltips: {
            callbacks: {
                label: function(tooltipItem, data) {
                    var label = data.datasets[tooltipItem.datasetIndex].label || '';

                    label = logic to transform label from old to new
    
                    return label;
                }
            }
        }

Documentation of it: https://www.chartjs.org/docs/latest/configuration/tooltip.html#label-callback

Upvotes: 2

Related Questions