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

216
Views
Gráfico JS: muestra el porcentaje de etiquetas sin getContext ('2d')

Estoy usando la biblioteca chartJs para mostrar los datos que obtengo de mi base de datos MySQL. En la función a continuación, AddValuesToNavigatorChart toma los datos de los navegadores y los datos porcentuales y los muestra en el gráfico circular. Lo que necesito saber es cómo agregar '%' en mis etiquetas. Encontré pocas respuestas con getContent('2d')... usando la forma antigua, pero no funciona. Esta es la función:

 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

Proporcione la versión de chartjs que está utilizando.

¿Quiso decir que desea mostrar el % en la etiqueta de la información sobre herramientas?

Para la versión v3.8.0, aquí hay un código de trabajo que acabo de hacer, Enlace

Como opción, puede editar la etiqueta de información sobre herramientas como desee:

 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!