0

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?

bubbles
  • 861
  • 4
  • 13
  • 30

1 Answers1

2

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']});
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • I see. So it is a completely valid approach to load the visualizations API when the App is loading (even though you will not be displaying anything just yet). If the only charts I need are included in corechart, then I do not have to worry about loading anything else while the user is using my app. Please confirm. – bubbles Mar 24 '13 at 18:58
  • Yup.loading everthing at load time is not an better approach.it depends on our app.if we are using many charts then i would prefer loading at a time.but we have only 2 ways of loading...i would prefer runner method. – Suresh Atta Mar 24 '13 at 19:14
  • Sorry, i am having a hard time understanding that. So if for instance, the only chart you are using is a PieChart, and you have lots of those in your application, then loading the Piechart API can be done at application startup since, you are only using one type of chart. (you do not need to request to load the visualization again since you already have the PieChart API loaded) – bubbles Mar 24 '13 at 20:42
  • In that case also we have to load to our machine because a wrapper is loadrd but not actually downloaded..we have to call runner eachtime.no other option i did' nt found. – Suresh Atta Mar 25 '13 at 05:31
  • So you are saying that if you want to have 2 PieCharts, you have to run 2 runnable instances? Is it not enough to only use 1 Runnable, and then use whatever it loads to render the other one, possible more than 2. What does it mean "wrapper is loaded but not actually downloaded" – bubbles Mar 25 '13 at 07:10
  • As we can't store it on client side (which is downloaded by AJAX),we have to go for runnable method each time :( which is i am doing now..i am keep working on charts these days i'll let you know if got any fix for this.cheers. – Suresh Atta Mar 25 '13 at 07:26
  • And i am talking about this https://developers.google.com/chart/interactive/docs/reference#chartwrapperobject and did'nt finda way out in GWT. – Suresh Atta Mar 25 '13 at 07:43