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

148
Views
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 answers
Answer question

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 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!