Chart.js v2 not rendering in Angular 2

I was able to render charts with v1.0.2 in Angular 2, but with v2.0.0 it doesn’t render anything in the screen and doesn’t log anything on the console.

I’m using the example provided in v2 docs:

constructor(el: ElementRef) {}

ngAfterViewInit() {
    var ctx = this.el.nativeElement.firstChild.getContext("2d");
    var myChart = new Chart(ctx, {
        type: 'bar',
        data: {
            labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
            datasets: [{
                    label: '# of Votes',
                    data: [12, 19, 3, 5, 2, 3]
            }]
        },
        options:{
            scales:{
                yAxes:[{
                        ticks:{
                            beginAtZero:true
                        }
                    }]
            }
        }
      });
  }

Author: Fantashit

1 thought on “Chart.js v2 not rendering in Angular 2

Comments are closed.