问题
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