Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
Chart JS : Display the percentage of labels without getContext('2d')

I'm using the library chartJs to display the data that i get from my MySQL database. In the fucntion below, AddValuesToNavigatorChart takes the browsers data and the percentage data and displays them on the pie chart. What i need to know, is how to add '%' in my labels ? I found few answer with getContent('2d').. using the old way, but it's not working. This is the function :

 function AddValuesToNavigatorChart(browsers, percentage) {
            checkNavigatorChart()
            const data = {
                labels: browsers,
                datasets: [{
                    data: percentage,
                    backgroundColor: [
                        'rgb(192,192,192)',
                        'rgb(255,0,0)',
                        'rgb(0,0,0)',
                        'rgb(105,105,105)'
                    ],
                    hoverOffset: 4
                }]
            };
            const config = {
                tooltips: {
                    enabled: false
                },
                type: 'pie',
                data: data,
                plugins: [ChartDataLabels],
                options: {
                    showTooltips: false,
                    plugins: {
                        datalabels: {
                            color: 'rgb(255,255,255)',
                            borderWidth: '2',
                            align: 'top'
                        },
                        legend: {
                            position: 'bottom',
                            align: 'center',
                            labels: {
                                boxWidth: 12,
                                padding: 15,
                                usePointStyle: true,
                                pointStyle: 'circle'
                            }
                        },
                        title: {
                            text: 'Navigator Chart',
                            display: true,
                            color: 'rgb(0,0,0)',
                            position: 'top'
                        }
                    }
                }
            };
            const NavigatorChart = new Chart(
                document.getElementById('NavigatorChart'),
                config
            );
        }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Please provide the version of chartjs that you are using.

Did you mean you want to show the % in the label of the tooltip?

For version v3.8.0, here is a working code I have just made, Link

As in option, you can edit the label of tooltip as you want:

options: {
    plugins: {
      tooltip: {
        callbacks: {
          label: (tooltipItem) => {
              //tooltipItem is for the slice of the pie you are hovering now
              return ' ' + tooltipItem.parsed + '%';
            },
        }
      }
    }
  }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!