I added this to my html:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
I have this method in my gwt code:
public static native void getVisual() /*-{
google.load("visualization", "1", {packages:["piechart"]});
function drawChart() {
var data = new $wnd.@google.visualization::DataTable();
data.addColumn('string', 'Task');
data.addColumn('number', 'Hours per Day');
data.addRows(5);
data.setValue(0, 0, 'Work');
data.setValue(0, 1, 11);
data.setValue(1, 0, 'Eat');
data.setValue(1, 1, 2);
data.setValue(2, 0, 'Commute');
data.setValue(2, 1, 2);
data.setValue(3, 0, 'Watch TV');
data.setValue(3, 1, 2);
data.setValue(4, 0, 'Sleep');
data.setValue(4, 1, 7);
var chart = new
google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, {width: 400, height: 240, is3D: true, title:
'My Daily Activities'});
}
}-*/;
Whenever i compile, however, i get this error:
Line 369: Unresolvable native reference to type 'google.visualization'
Line 369 is: var data = new $wnd.@google.visualization::DataTable();
I am not a javascript developer, and as such have never used jsni
before. The two resources that I have been referencing are:
http://code.google.com/apis/visualization/documentation
and
http://code.google.com/webtoolkit/documentation/com.google.gwt.doc.DeveloperGuide.JavaScriptNativeInterface.html
Thanks -
Jeremiah
here is the current method:
public static native void getVisual() /*-{
$wnd.google.load("visualization", "1", {packages:["piechart"]});
function drawChart() {
var data = new $wnd.google.visualization.DataTable();
data.addColumn('string', 'Task');
data.addColumn('number', 'Hours per Day');
data.addRows(5);
data.setValue(0, 0, 'Work');
data.setValue(0, 1, 11);
data.setValue(1, 0, 'Eat');
data.setValue(1, 1, 2);
data.setValue(2, 0, 'Commute');
data.setValue(2, 1, 2);
data.setValue(3, 0, 'Watch TV');
data.setValue(3, 1, 2);
data.setValue(4, 0, 'Sleep');
data.setValue(4, 1, 7);
var chart = new
$wnd.google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, {width: 400, height: 240, is3D: true, title: 'My
Daily Activities'});
}
}-*/;
Now, when i call the function the entire screen goes blank, in the
hosted browser and in external browsers.
Firebug reports this however:
com_google_gwt_lang_Exceptions_caught__Ljava_lang_Object_2 is not defined
com_google_gwt_user_client_DOM_dispatchEventAndCatch__Lcom_google_gwt_user_client_Event_2Lcom_google_gwt_user_client_Element_2Lcom_google_gwt_user_client_EventListener_2Lcom_google_gwt_core_client_GWT$UncaughtExceptionHandler_2(undefined,
undefined, undefined, undefined)369BA166...ache.html (line 4826)
com_google_gwt_user_client_DOM_dispatchEvent__Lcom_google_gwt_user_client_Event_2Lcom_google_gwt_user_client_Element_2Lcom_google_gwt_user_client_EventListener_2(click
clientX=96, clientY=185, div.txclick, )369BA166...ache.html (line
4813)
com_google_gwt_user_client_impl_DOMImplStandard_dispatchEvent()(click
clientX=96, clientY=185)369BA166...ache.html (line 5257)
[Break on this error] $e0 =
com_google_gwt_lang_Exceptions_caught__Ljava_lang_Object_2($e0);
firebug is also reporting that the gaspi script is already downloaded
when this happens.
Once again this is my first use of jsni, so don't assume i know what i
am doing here - It could be a very easy/stupid problem.
-Jeremiah Elliott
I am currently adding the visualizations using:
var chart = new
$wnd.google.visualization.PieChart($doc.getElementById('chart_div'));
However, I want to add them to a gwt widget container, i.e, have a
HorizontalPanel that I could add these Visualizations objects to.
How would i do that? Is there a correlation between the DOM elements
and the GWT widgets?
Thanks
-Jeremiah