[Chartjs]-Usage of Chartjs in Angular2 App

1๐Ÿ‘

โœ…

You can use npm module:

angular2-chartjs

Then you can use it like this in your module:

import { ChartModule } from 'angular2-chartjs';

@NgModule({
  imports: [ ChartModule ]
  // ...
})
export class AppModule {
}

And in html template:

<chart [type]="type" [data]="data" [options]="options"></chart>

Donโ€™t forget to fill it with data ๐Ÿ˜‰

1๐Ÿ‘

Something like:

@Component({
  selector: 'my-component',
  template: `
<canvas #myChart" width="400" height="400"></canvas>
<script>
`)}
export class MyComponent {
  @ViewChild('myChart') myChart;

  ngAfterViewInit() {
    var myChart = new Chart(this.target.nativeElement, {[...]});
  }
}

Leave a comment