Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
Cannot read properties of null (reading 'getContext') at new EchartsDropdownComponent
import { Component, Input, OnChanges } from "@angular/core";
import { Chart } from 'chart.js'


@Component({
   selector: "ngx-echarts-dropdown",
   template: `<canvas id="myChart" width="400" height="400"></canvas>`
}) 
export class EchartsDropdownComponent implements OnChanges {


   canvas = <HTMLCanvasElement> document.getElementById('myChart');

   ctx = this.canvas.getContext('2d');

    myChart = new Chart(this.ctx, {
       data: {
          datasets: [{
               label: 'Scatter Dataset',
               data: [{
                     x: -10,
                     y: 0
               }, {
                     x: 0,
                     y: 10
               }, {
                     x: 10,
                     y: 5
               }]]
          }]
       },
       options: {
             scales: {
                  xAxes: [{
                     type: 'linear',
                     position: 'bottom'
                  }]
             }
         }
   });

I am trying to plot scatter graph in Angular 12. Am getting below error.

enter image description here

Please help me with solution for the same

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should place the chart creation code inside the method ngAfterViewInit and don't forget to specify the chart type.

export class EchartsDropdownComponent implements AfterViewInit, OnChanges {

  ngAfterViewInit() {
    myChart = new Chart('myChart', {
      type: 'scatter', // <- define the chart type
      data: {
        datasets: [{
          label: 'Scatter Dataset',
          ...
  }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda