google-apps-script - 我可以访问图表中选定的数据吗

标签 google-apps-script google-visualization

我使用 Google Apps 脚本创建了一个用户界面,用于显示图表对象(例如 TableChart 和 PieChart)中的数据。

图表对象允许用户选择饼图的一部分和表中的多条线。我希望我的代码知道图表中选定的数据是什么。

我有办法做到这一点吗? 如果没有,我将在 GAS 问题跟踪器中填写功能请求。

谢谢

蒂埃里

最佳答案

是的。请参阅 getSelection() 的文档

getSelection() [optional]

This is optionally exposed by visualizations that want to let you access the currently selected data in the graphic.

selection_array getSelection()

Returns

selection_array An array of selected objects, each one describing a data element in the underlying table used to create the visualization (a DataView or a DataTable). Each object has properties row and/or column, with the index of the row and/or column of the selected item in the underlying DataTable. If the row property is null, then the selection is a column; if the column property is null, then the selection is a row; if both are non-null, then it is a specific data item. You can call the DataTable.getValue() method to get the value of the selected item. The retrieved array can be passed into setSelection().

Example

function myClickHandler(){
  var selection = myVis.getSelection();


  for (var i = 0; i < selection.length; i++) {
    var item = selection[i];
    if (item.row != null && item.column != null) {
      message += '{row:' + item.row + ',column:' + item.column + '}';
    } else if (item.row != null) {
      message += '{row:' + item.row + '}';
    } else if (item.column != null) {
      message += '{column:' + item.column + '}';
    }
  }
  if (message == '') {
    message = 'nothing';
  }
  alert('You selected ' + message);
}

关于google-apps-script - 我可以访问图表中选定的数据吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14504014/

相关文章:

google-apps-script - 谷歌表格: Prevent the unchecking of a checkbox after it has been checked

javascript - 谷歌可视化折线图无法显示自定义点

ios - 在iPhone和移动设备上显示图表

javascript - 谷歌图表显示所有标签

javascript - 谷歌图表 : Adding points to a candlestick chart

javascript - 使用 Google Apps 脚本和 JavaScript 从 google 表中反射(reflect) HTML 中的选项值

google-apps-script - getDataRange().getValues() 无法识别使用 setValue 更改的单元格值

google-apps-script - 用于多个工作表的单个 Google 表单

google-apps-script - Google 应用程序脚本的数据分析库

javascript - (谷歌图表)我想在鼠标悬停时在工具提示中显示折线图 Y 值?