我使用 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/