Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <a href="http://code.google.com/p/gwt-google-apis/" rel="nofollow">Google API Libraries for Google Web Toolkit</a> (such as gwt-visualization.jar) are only meant for use on the client side (for generating javascript). Fortunately Google also provides the server-side java code for publishing DataTables in their <a href="http://code.google.com/p/google-visualization-java/" rel="nofollow">Google Visualization Data Source Library</a>. </p> <p>Here is the setup that allowed me to generate DataTables on the server in a remote procedure call, pass them back to the client as a JSON string, and use Google Visualizations for Google Web Toolkit to display a nice Google Plot on the client web page. I am using Eclipse Indigo with Google Web Toolkit 2.4.0. </p> <ul> <li>Add the <a href="http://gwt-google-apis.googlecode.com/files/gwt-visualization-1.1.2.zip" rel="nofollow">gwt-visualization.jar</a> GWT API binding client library to your project's build path, and as an inherited module in your own module's description:</li> </ul> <p>In src/com.package.name/project-name.xml : </p> <pre><code>&lt;inherits name='com.google.gwt.visualization.Visualization'/&gt; </code></pre> <ul> <li>Add the jar for the <a href="http://code.google.com/p/google-visualization-java/" rel="nofollow">Google Visualization Data Source Library</a> and all the included dependency jars to PROJECT/war/WEB-INF/lib for the server code to use</li> <li>Define a remote procedure interface that returns a String:</li> </ul> <p>In client/TableService.java :</p> <pre><code>package com.clark.demos.client; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @RemoteServiceRelativePath("table") public interface TableService extends RemoteService { String getTable(); } </code></pre> <p>In client/TableServiceAsync.java :</p> <pre><code>package com.clark.demos.client; import com.google.gwt.user.client.rpc.AsyncCallback; public interface TableServiceAsync { void getTable( AsyncCallback&lt;String&gt; callback ); } </code></pre> <p>In war/WEB-INF/web.xml : </p> <pre><code> &lt;servlet&gt; &lt;servlet-name&gt;tableServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;com.clark.demos.server.TableServiceImpl&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;tableServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/google_visualization___gwt/table&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <ul> <li>Implement the "table" service on the server:</li> </ul> <p>In server/TableServiceImpl.java :</p> <pre><code>package com.clark.demos.server; import com.google.visualization.datasource.datatable.ColumnDescription; import com.google.visualization.datasource.datatable.DataTable; import com.google.visualization.datasource.datatable.value.ValueType; import com.google.visualization.datasource.render.JsonRenderer; @SuppressWarnings("serial") public class TableServiceImpl extends RemoteServiceServlet implements TableService { @Override public String getTable() { DataTable data = new DataTable(); data.addColumn( new ColumnDescription("Task", ValueType.TEXT, "Task") ); data.addColumn( new ColumnDescription("Stemming", ValueType.NUMBER, "Stemming") ); data.addColumn( new ColumnDescription("NoStemming", ValueType.NUMBER, "No Stemming") ); data.addRowFromValues( "Fire", 1.0, 0.8 ); data.addRowFromValues( "Flood", 0.5, 0.65 ); return JsonRenderer.renderDataTable(data, true, false, false).toString(); } } </code></pre> <ul> <li>Have client code call the "table" service and construct a DataTable from the returned JSON string:</li> </ul> <p>In client/gwt-visualization-demo.java : </p> <pre><code>/** * Create a remote service proxy to talk to the server-side Table service. */ private final TableServiceAsync tableService = GWT .create(TableService.class); public static native DataTable toDataTable(String json) /*-{ return new $wnd.google.visualization.DataTable(eval("(" + json + ")")); }-*/; public void onModuleLoad() { // Create a callback to be called when the visualization API // has been loaded. Runnable onLoadCallback = new Runnable() { public void run() { final Panel panel = RootPanel.get(); tableService.getTable(new AsyncCallback&lt;String&gt;() { @Override public void onSuccess(String result) { AbstractDataTable data = toDataTable(result); BarChart pie = new BarChart(data, createOptions()); pie.addSelectHandler(createSelectHandler(pie)); panel.add(pie); } @Override public void onFailure(Throwable caught) { } }); } }; // Load the visualization api, passing the onLoadCallback to be called // when loading is done. VisualizationUtils.loadVisualizationApi(onLoadCallback, BarChart.PACKAGE); </code></pre> <p>}</p> <p>Example code found at <a href="https://github.com/RichDickClark/gwt-google-charts-demo.git" rel="nofollow">https://github.com/RichDickClark/gwt-google-charts-demo.git</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload