2016-04-26 23 views
1

現在、TypeScriptと組み合わせてAngular2を調べており、Chartjsモジュールをアプリケーションに組み込みたいと考えています。 chartjs documentationでは一般的なキャンバスhtmlタグを使用してそれを行う方法を示します。Angular2 AppでChartjsを使用する

<canvas id="myChart" width="400" height="400"></canvas> 
<script> 
var ctx = document.getElementById("myChart"); 
var myChart = new Chart(ctx, {[...]}); 
</script> 

私はAngular2と活字体で同様のことを行うことができますどのように?

ありがとうございます!

答えて

1

angular2-chartjs

次に、あなたがあなたのモジュールでこのようにそれを使用することができます:

import { ChartModule } from 'angular2-chartjs'; 

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

とHTMLでのテンプレート:

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

データとそれを埋めるために忘れないでください。)

+0

ありがとう!魅力的な作品 –

1

ような何か:あなたはNPMモジュールを使用することができます

@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, {[...]}); 
    } 
} 
関連する問題