如何获取数据事件在Google角图表> 2+中的点击

问题描述 投票:0回答:1

我在角度项目仪表板中使用了Google图表。

enter image description here

通过阅读文档: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>`

Component.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);
}

但是我没有得到我选择的值。enter image description here

我需要成熟度和年份的值...我如何得到的??我进行了任何更改吗?

angular6 angular5 angular7 react-google-charts
1个回答
0
投票

选择当选择图表中的元素时,将发出select事件。

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

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

在组件中

onSelect(event){
    // your click event logic
}

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

© www.soinside.com 2019 - 2024. All rights reserved.