Sunday, November 27, 2011

Re: GWT DataTable issue

To answer my own question...  I needed to load the visualization api explicitly in GWT for it to work.  Below is the code for the next guy that hits this.

Thanks,
Phil

 
   // Create a callback to be called when the visualization API
   // has been loaded.
   Runnable onLoadCallback = new Runnable() {
     public void run() {
     drawOrgChart();
     }
   };

   // Load the visualization api, passing the onLoadCallback to be called
   // when loading is done.
   VisualizationUtils.loadVisualizationApi(onLoadCallback, OrgChart.PACKAGE);

On Mon, Nov 28, 2011 at 1:23 AM, Phil McDonnell <phil.a.mcdonnell@gmail.com> wrote:
I'm trying to use OrgChart from google's visualization api. I get the includes and jars setup alright, but anytime I try to initialize a DataTable (which is needed to populate the OrgChart) I get a very opaque error that is pasted below.  Has any one seen something like this?

I'm literally just copy and pasting a few lines of sample code from various places online. I have include my sample code below as well as the error I am seeing. I believe I'm including the visualization jar and I've added the corresponding xml line for the visualization library to my *.gwt.xml file.  I searched around quite a bit, but can't seem to find this error elsewhere.  I'm on GWT 2.2 and AppEngine 1.5.1.

Thanks,
Phil

Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError): Cannot read property 'visualization' of undefined __gwt_ObjectId: 13 at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:129) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561) at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269) at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) at com.google.gwt.visualization.client.DataTable$.create(DataTable.java) at dorsata.client.Dorsata.createDataTable(Dorsata.java:264) at dorsata.client.Dorsata.drawOrgChart(Dorsata.java:224) at dorsata.client.Dorsata.onModuleLoad(Dorsata.java:81) ... 9 more

Sample code I'm using:
 public void drawOrgChart() {
       Widget widget;
       Options options = Options.create();
       options.setAllowHtml(true);
       options.setAllowCollapse(true);
       options.setColor("#00FF00");
       options.setSelectionColor("#FF0000");
       widget = new OrgChart(createDataTable(), options);
       RootPanel.get().add(widget);
           }
 private AbstractDataTable createDataTable() {
   DataTable data = DataTable.create();
   data.addColumn(ColumnType.STRING, "Name");
   data.addColumn(ColumnType.STRING, "Manager");
   data.addRows(5);
   data.setValue(0, 0, "Mike");
   data.setValue(1, 0, "Jim");
   data.setValue(1, 1, "Mike");
   data.setValue(2, 0, "Alice");
   data.setValue(2, 1, "Mike");
   data.setValue(3, 0, "Bob");
   data.setValue(3, 1, "Jim");
   data.setValue(4, 0, "Carol");
   data.setValue(4, 1, "Bob");
   return data;
         }



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment