Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何在Angular 4中添加Google图表大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在角度4应用程序中集成谷歌图表? @H_262_1@我读了SO问题here的答案,但我认为它不完整.基本上,我正在使用GoogleChartComponent和扩展它的另一个组件尝试与前一个答案相同的策略.出现两个错误,第一个是对子组件的super()缺少调用,第二个是在此代码调用“new”

createBarChart(element: any): any {
      return new google.visualization.barChart(element);
  }
@H_262_1@我收到错误“google.visualization.barChart不是构造函数”.

@H_262_1@我看到其中一条评论也提到了使用< ng-content>用于数据投影,但没有明确概述.

@H_262_1@在尝试提出“好”的问题时,这是我的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);
  }
}
@H_262_1@我的子组件扩展了它:

@Component({
  SELEctor: 'app-bitcoin-chart',template: `
   <div id="barchart_material" style="width: 700px; height: 500px;"></div>
  `,styles: []
})
export class BitcoinChartComponent extends GoogleChartComponent  {
 private options;
  private data;
  private chart;
  // constructor() {
  //   super();
  //   console.log('Bitcoin Chart Component');
  // }
  drawGraph() {
    console.log('Drawing Bitcoin Graph');
    this.data = this.createDataTable([
     ['Price','Coinbase','Bitfinex','Poloniex','Kraken'],['*',1000,400,200,500]
    ]);

    this.options = {
     chart: {
                    title: 'Bitcoin Price',subtitle: 'Real time price data across exchanges',},bars: 'vertical' // required for Material Bar Charts.
    };

    this.chart = this.createBarChart(document.getElementById('barchart_material'));
    this.chart.draw(this.data,this.options);
  }
}
@H_675_18@
google.visualization.barChart是’corechart’包的一部分 @H_262_1@需要更改加载语句…

google.charts.load('current',{
    'packages': ['corechart']
  });
@H_262_1@‘bar’包用于Material图表版本
这将是 – > google.charts.bar

@H_262_1@但是,Material Chart不支持许多配置选项…

@H_262_1@有关不受支持的选项的完整列表 – > Tracking Issue for Material Chart Feature Parity

大佬总结

以上是大佬教程为你收集整理的如何在Angular 4中添加Google图表全部内容,希望文章能够帮你解决如何在Angular 4中添加Google图表所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。