GoogleVisualization:过滤的选择项

GoogleVisualization: filtered selection items

本文关键字:选择 过滤 GoogleVisualization      更新时间:2023-09-26

在Google可视化中,我实现了一个带有表格和一些控制过滤器的仪表板。

现在假设我有以下数据表:

data = new google.visualization.DataTable();
data.addColumn('string','Name');
data.addColumn('number', 'Age');
 data.addRows([
      ['Customer1', 85],
      ['Customer2', 20],
      ['Customer3', 30],
    ]);

如果我选择第一行(Customer1)并且我做:

var tmpData = table.getChart().getSelection();
var stringCustomer = data.getValue(tmpData.row, 0)

stringCustomer是"Customer1".

现在我筛选表格图表,只显示年龄==30的客户:我只有一行是Customer3,我选择了那一行。

var tmpData = table.getChart().getSelection();
var stringCustomer = data.getValue(tmpData.row, 0)

在此代码中,stringCustomer总是Customer1。我如何取得Customer3?getValue()如何返回图表上显示项的项?

选择返回表或图表所看到的数据中所选元素的索引,而不是基本DataTable。仪表板向每个ChartWrapper传递一个DataView,您可以通过ChartWrapper#getDataTable方法访问它。使用此命令获取数据:

var selection = table.getChart().getSelection(),
    view = table.getDataTable(),
    stringCustomer;
// loop over all selected rows
for (var i = 0; i < selection.length; i++) {
    stringCustomer = view.getValue(selection[i].row, 0);
    // do something with stringCustomer
}