我目前正在探索 Angular2 与 TypeScript 的结合,我想在我的应用程序中包含 Chartjs 模块。在 chartjs documentation显示了如何使用常见的 canvas html 标签来做到这一点:
<canvas id="myChart" width="400" height="400"></canvas>
<script>
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {[...]});
</script>
如何使用 Angular2 和 TypeScript 做类似的事情?
提前致谢!
最佳答案
您可以使用 npm 模块:
然后你可以在你的模块中像这样使用它:
import { ChartModule } from 'angular2-chartjs';
@NgModule({
imports: [ ChartModule ]
// ...
})
export class AppModule {
}
在 html 模板中:
<chart [type]="type" [data]="data" [options]="options"></chart>
不要忘记用数据填充它;)
关于node.js - Chartjs 在 Angular2 应用程序中的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36869875/