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

110
Views
Personalice los colores de relleno para ChartJS 3.x usando el evento del complemento beforRender

Intento aplicar el código que puedo ver en esta pregunta: https://github.com/chartjs/Chart.js/issues/3071

pero no puedo entender cómo cambiar el código para que funcione en chartJS v3.x

 this.ChartInst = new Chart(this._ctx, { type: "line", data: this._data , options: this._chartoptions, plugins: [{ beforeRender: function (c, args, options) { var gradientFill = c.ctx.createLinearGradient(0, 0, 0, c.height); gradientFill.addColorStop(0.4, 'rgba(223,140,255,0.25)'); gradientFill.addColorStop(0.6, 'rgba(83, 155, 243, 0.25)'); var model = c.data.datasets[0]; model.backgroundColor = gradientFill; //console.log(model) } }] })

se llama al evento, y cuando consola.log el modelo var, puedo ver que backgroundColor está configurado en CanvasGradient pero no sucede nada en el gráfico. (Solo fondo gris predeterminado)

¿Alguna idea? Gracias

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

0

Después de algunas búsquedas, encontré una solución cambiando el evento del complemento a beforeDraw y llamando al método update() del gráfico.

 this.ChartInst = new Chart(this._ctx, { type: "line", data: this._data , options: this._chartoptions, plugins: [{ beforeDraw: function (c, a, o) { var yScale = c.scales['y']; var max = c.data.datasets[0].data.reduce(function (prev, current) { return (prev.y > current.y) ? prev : current }).y; var yPos = yScale.getPixelForValue(max); var gradientFill = c.ctx.createLinearGradient(0, yPos, 0, c.height); gradientFill.addColorStop(0.4, 'rgba(83, 155, 243, 0.25)'); gradientFill.addColorStop(0.9, 'rgba(223,140,255,0.25)'); c.data.datasets[0].backgroundColor = gradientFill; c.update(); } }] })
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!