GWT Visualization API VisualizationUtils.LoadVisualizationApi

回眸只為那壹抹淺笑 提交于 2020-01-17 03:56:04

问题


Assume an application exists where you have multiple different views, each containing multiple graphs of the same type.

My question is, do I need to load the visualization API each time I create a new graph as shown in this example http://code.google.com/p/gwt-google-apis/wiki/VisualizationGettingStarted, or if I load the visualization once, do I no longer have to create a Runnable in order to wait when the visualization is loaded so the data can be displayed?


回答1:


Yes,We cannot use Google Charts Offline.

As we cannot download the Google Visualization api to our local machine,We have to load them dynamically.

The runnable way

  Runnable onLoadCallback = new Runnable() {
                      public void run() 
                      {
  PieChart pie = new PieChart(createTable(result), createOptions());
  pie.addSelectHandler(createSelectHandler(pie));
   dataCHTabel.clear();
    dataCHTabel.add(pie);
    }
    };
   VisualizationUtils.loadVisualizationApi(onLoadCallback, PieChart.PACKAGE);

New way of Visualization API loading:

The above line is deprecated and the new way of loading all charts is

VisualizationUtils.loadVisualizationApi(onLoadCallback, CoreChart.PACKAGE);  

By Loading all packages while app loading

By adding the below code on my host page(appname.html)

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
 <script type="text/javascript">
    google.load("visualization", "1", {'packages' : ["corechart"] });
 </script>

The corechart package includes the code for the new versions of the area, bar, column, line, pie, and scatter visualizations, which were previously loaded by separate packages.

and then

 PieChart pie = new PieChart(createTable(result), createOptions());
 pie.addSelectHandler(createSelectHandler(pie));
 dataCHTabel.clear();
 dataCHTabel.add(pie);

geochart not included in core So ,And if you want to load geo chart ,you have to add

google.load('visualization', '1', {'packages': ['geochart']});


来源:https://stackoverflow.com/questions/15593243/gwt-visualization-api-visualizationutils-loadvisualizationapi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!