Chartjs-I am getting TS2339: Property 'chart' does not exist on type 'Window'?

0👍

in case you trying to follow this tutorial:

i found some things that doesnt run for me.

For make things running i changed the code as following:

    import { Component, ElementRef, OnInit } from '@angular/core';
import { WeatherService } from './weather.service';
import { Chart } from 'chart.js';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

  chart = [];

  constructor(private _weather: WeatherService, private element: ElementRef) { }

  ngOnInit() {

    let ctx = this.element.nativeElement.querySelector('#canvas').getContext('2d');
    let chart = new Chart(ctx, {
      // The type of chart we want to create
      type: 'line',

      // The data for our dataset
      data: {
        labels: ["January", "February", "March", "April", "May", "June", "July"],
        datasets: [{
          label: "My First dataset",
          backgroundColor: 'rgb(255, 99, 132)',
          borderColor: 'rgb(255, 99, 132)',
          data: [0, 10, 5, 2, 20, 30, 45],
        }]
      },

      // Configuration options go here
      options: {}
    });

  }
}

Hope that helps

Leave a comment