如何在角度4应用程序中集成谷歌图表?
我在这里阅读了SO问题的答案,但我认为它不完整.基本上,我正在尝试与之前的答案相同的策略,使用GoogleChartComponent和扩展它的另一个组件.出现两个错误,第一个是对子组件的super()缺少调用,第二个是在此代码中调用"new"
createBarChart(element: any): any {
return new google.visualization.BarChart(element);
}
Run Code Online (Sandbox Code Playgroud)
我收到错误"google.visualization.BarChart不是构造函数".
我看到其中一条评论也提到了<ng-content>数据投影的使用,但没有明确概述.
在尝试提出一个"好"的问题时,这是我的GoogleChartComponent:
export class GoogleChartComponent implements OnInit {
private static googleLoaded: any;
constructor() {
console.log('Here is GoogleChartComponent');
}
getGoogle() {
return google;
}
ngOnInit() {
console.log('ngOnInit');
if (!GoogleChartComponent.googleLoaded) {
GoogleChartComponent.googleLoaded = true;
google.charts.load('current', {
'packages': ['bar']
});
google.charts.setOnLoadCallback(() => this.drawGraph());
}
}
drawGraph() {
console.log('DrawGraph base class!!!! ');
}
createBarChart(element: any): any {
return new google.visualization.BarChart(element);
}
createDataTable(array: any[]): any {
return google.visualization.arrayToDataTable(array);
}
} …Run Code Online (Sandbox Code Playgroud) 我可以用nvm设置node版本,但是VS code中的终端恢复到7.6.0,这与yarn有问题!
\n\n编辑: [在 VS 代码之外从 zsh 添加调试信息]
\n\n\xce\xbb ~ which node \n/Users/Freddy/.nvm/versions/node/v9.6.1/bin/node\n\xce\xbb ~ node -v \nv9.6.1\n\xce\xbb ~ nvm --version \n0.33.8\nRun Code Online (Sandbox Code Playgroud)\n\n我使用 nvm 来管理不同版本的节点,除了 VS Code 之外,它工作得很好。
\n\n在 VS Code 终端中,节点版本始终恢复为 v7.6.0:
\n\nnode -v \nv7.6.0\n\n\xce\xbb ~/auth0-profile nvm use default \nNow using node v9.6.1 (npm v5.6.0)\n\n\xce\xbb ~/auth0-profile node -v \n\nv7.6.0\n\n\xce\xbb ~/auth0-profile nvm current \nsystem\n\n\xce\xbb ~/auth0-profile nvm ls \n v8.9.4\n v8.10.0\n v9.6.1\n-> system\ndefault -> 8.10.0 (-> v8.10.0)\nsystem -> 9.6.1 (-> v9.6.1)\nnode …Run Code Online (Sandbox Code Playgroud)