Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在Angular2应用程序中使用Chartjs_Node.js_Typescript_Angular_Chart.js - Fatal编程技术网

Node.js 在Angular2应用程序中使用Chartjs

Node.js 在Angular2应用程序中使用Chartjs,node.js,typescript,angular,chart.js,Node.js,Typescript,Angular,Chart.js,我目前正在探索Angular2与TypeScript的结合,我想在我的应用程序中包括Chartjs模块。中显示了如何使用公共画布html标记执行此操作: <canvas id="myChart" width="400" height="400"></canvas> <script> var ctx = document.getElementById("myChart"); var myChart = new Chart(ctx, {[...]}); </

我目前正在探索Angular2与TypeScript的结合,我想在我的应用程序中包括Chartjs模块。中显示了如何使用公共画布html标记执行此操作:

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

var ctx=document.getElementById(“myChart”);
var myChart=新图表(ctx,{[…]});
如何使用Angular2和TypeScript执行类似的操作

提前谢谢

类似于:

@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, {[...]});
  }
}
@组件({
选择器:“我的组件”,
模板:`

您可以使用npm模块:

然后,您可以在模块中这样使用它:

import { ChartModule } from 'angular2-chartjs';

@NgModule({
  imports: [ ChartModule ]
  // ...
})
export class AppModule {
}
在html模板中:

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


别忘了用数据填充它;)

谢谢!工作起来很有魅力