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

301
Views
Cómo cambiar el color de fondo del gráfico al exportar a PDF con chart.js

Soy nuevo en chart.js e intento agregar un botón que exporte mi gráfico a un archivo PDF.

El gráfico se exporta con un fondo negro; sin embargo, quiero cambiar el fondo a blanco.

Intenté agregar el siguiente código para cambiar el fondo, pero no estoy seguro de dónde me equivoco.

¿Cómo cambiaría el fondo del gráfico para que sea blanco cuando exporte a PDF?

 const bgColor = { id: 'bgColor', beforeDraw: (chart, steps, options) => { const {ctx, width, height} = chart; ctx.fillStyle = options.backgroundColor; ctx.fillRect(0, 0, width, height) ctx.restore(); } } var options = { responsive: true, maintainAspectRatio: true, scale: { min: 0, max: 10, stepSize: 1 }, scales: { r: { pointLabels: { font: { size: 15 } } } }, plugins: { bgColor: { backgroundColor: 'white' }, legend: { labels: { boxWidth: 0, font: { size: 30 } } } } } const radarChart = new Chart(document.getElementById('radarChart'), { type: 'radar', data: data, options: options })

Gráfico pdf

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Esto se debe a que nunca registra su complemento, por lo que no hace nada. Puede registrarlo localmente en un solo gráfico como este:

 const bgColor = {}; // Plugin Code const chart = new Chart('canvasId', { data: data, options: options, plugins: [bgColor] });

O puede registrarlo localmente para que se aplique a todos los gráficos de la siguiente manera:

 const bgColor = {}; // Plugin Code Chart.register(bgColor); // V3 syntax Chart.plugins.register(bgColor) // V2 syntax
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!