0

我在我的角度项目仪表板中使用了谷歌图表。

在此处输入图像描述

通过阅读文档:https ://github.com/FERNman/angular-google-charts ,我使用下面的代码来获取事件(它应该包含我选择的图表元素)

根据文档,当图表中的元素被选中时,会发出 select 事件。

<google-chart (select)="onSelect($event)"></google-chart>

我在我的代码中使用了相同的方法。

html:`

      <google-chart #chart [title]="Bartitle" [type]="Bartype" [data]="Bardata" [columnNames]="BarcolumnNames"
        [options]="Baroptions" [width]="Barwidth" [height]="Barheight" 
        (select)="onSelect($event)">
      </google-chart>`

组件.Ts

this.Bartitle = 'Current and Target';
this.Bartype = 'BarChart';
this.Bardata = [
  ["2012", 900, 390],
  ["2013", 1000, 400],
  ["2014", 1170, 440],
  ["2015", 1250, 480],
  ["2016", 1530, 540]
];
this.BarcolumnNames = ["Year", "Current", "Target"];
this.Baroptions = {
  hAxis: {
    title: 'Maturity'
  },
  vAxis: {
    title: 'Month'
  },
};
this.Barwidth = 200;
this.Barheight = 200;

onSelect(event) {
   console.log(event);
}

但我没有得到我选择的值..在此处输入图像描述

我需要成熟度和年份的值......我怎么得到它?我做了什么改变吗??

4

1 回答 1

1

Select 当图表中的元素被选中时,会发出 select 事件。

<google-chart (select)="onSelect($event)"></google-chart>

包含选定值数组的 ChartSelectionChangedEvent 类型的事件。

在组件中

编辑:基于评论

     onSelect(event) {
           const { row, column } = event[0];
           const year = this.Bardata[row][0];
           let selectedItem;
           if (column === 1) {
                selectedItem = "current";
           }
           if (column === 2) {
                selectedItem = "target";
           }
           console.log("year", year, "SelectedItem" ,selectedItem, this.Bardata[row][column]);
     }

有关更多信息,请阅读文档: https ://github.com/FERNman/angular-google-charts

于 2020-04-14T05:00:34.420 回答