简体   繁体   English

长期存在的谷歌可视化数据表?

[英]Long lived Google Visualization DataTable?

Is there an easy way to create a global / long lived instance of a google.visualization.DataTable() ?有没有一种简单的方法来创建google.visualization.DataTable()的全局/长寿命实例?

All the examples I've seen show it being created locally in a function, and that function then being a callback from the google.charts.load operation, either by specifying the callback directly in the load, or by using google.charts.setOnLoadCallback after the load.我见过的所有示例都表明它是在 function 中本地创建的,然后 function 是google.charts.load操作的回调,可以通过直接在加载中指定回调,也可以使用google.charts.setOnLoadCallback负载后。

But that then means that when the function ends the table goes out of scope and can't be used again.但这意味着当 function 结束时,表会从 scope 中消失,并且不能再次使用。

There are operations for adding and removing rows from a DataTable, which suggests that they can be "long lived", but I haven't seen an example of how to achieve this.有用于从 DataTable 添加和删除行的操作,这表明它们可以“长期存在”,但我还没有看到如何实现这一点的示例。

you can create a global variable.您可以创建一个全局变量。 then create the table after google loads...然后在谷歌加载后创建表......

var dataTable;

google.charts.load('current', {
  packages:['corechart']
}).then(function () {
  dataTable = google.visualization.DataTable();
  ...
});

then dataTable would be available until the page unloads...然后dataTable将可用,直到页面卸载...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM