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

235
Views
Gráfico JS: falta el título al borrar el lienzo si no hay datos disponibles

EDITAR: la respuesta a continuación funcionó bien, todo lo que hice aparte de eliminar chart.clear() fue ocultar la leyenda y los ejes x/y.

Sin embargo, ¿alguna idea de qué puede estar causando el texto borroso ahora?

Estoy seguro de que estoy haciendo algo notablemente tonto, pero parece que no puedo resolver esto.

Tengo el siguiente complemento global que mostrará el mensaje "No hay datos para mostrar" cuando corresponda:

 Chart.plugins.register({ afterDraw: function(chart, args, options) { if (chart.data.datasets.every(dataSetContainsNoData)) { debugger; var ctx = chart.chart.ctx; var width = chart.chart.width; var height = chart.chart.height; chart.clear(); ctx.save(); ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText('No data to display', width / 2, height / 2); } } });

Sin embargo, me gustaría mantener el título de este gráfico en la parte superior y no sé cómo hacerlo. Si inspecciono chart.chart.options , la opción de título tiene el texto establecido y el indicador de visualización está establecido en true .

Aquí están las opciones que están en el gráfico real.

 options: { title: { display: true, text: 'Chart Header Text' }, responsive: true, maintainAspectRatio: false, scales: { yAxes: [{ ticks: { beginAtZero: true } }] } }

¡Cualquier ayuda es muy apreciada!

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

0

Deberá comentar chart.clear() y el título debería funcionar.

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!