ajax - How to use Google Visualization chart with GWT and AjaxLoader -
i'm trying incorporate interactive charts gwt app using google visualization. don't want connect google app engine. i'd utilize gwt apis instead of embedding javascript in code. i'm trying follow examples simpleviz , helloajaxloader in gwt-google-apis, chart not load. i've added ajaxloader , visualization jars classpath , inherits in gwt.xml. in next code, alert "in onmoduleload" displays, not "in run".
my code:
public class simpleviz implements entrypoint { private verticalpanel container; private imagepiechart chart; public void onmoduleload() { window.alert("in onmoduleload"); container = new verticalpanel(); rootpanel.get().add(container); container.getelement().getstyle().setpropertypx("margin", 10); container.setspacing(10); container.add(new label("pie chart example")); ajaxloader.init(); ajaxloader.loadapi("visualization", "1", new runnable() { public void run() { window.alert("in run"); chart=new imagepiechart(); container.add(chart); draw(); } }, null); } private void draw() { // prepare info datatable datatable = datatable.create(); datatable.addcolumn(columntype.string, "task"); datatable.addcolumn(columntype.number, "hours per day"); datatable.addrows(5); datatable.setvalue(0, 0, "work"); datatable.setvalue(0, 1, 11); datatable.setvalue(1, 0, "sleep"); datatable.setvalue(1, 1, 7); datatable.setvalue(2, 0, "watch tv"); datatable.setvalue(2, 1, 3); datatable.setvalue(3, 0, "eat"); datatable.setvalue(3, 1, 2); datatable.setvalue(4, 0, "commute"); datatable.setvalue(4, 1, 1); // set options imagepiechart.options options = imagepiechart.options.create(); options.setbackgroundcolor("#f0f0f0"); options.setis3d(false); options.settitle("so, how day?"); // draw chart chart.draw(datatable, options); } }
as follow-up question, these libraries current , maintained or should different solution?
this how (and works).
in module gwt.xml file add together next line:
<inherits name="com.google.gwt.visualization.visualization"/>
this line inherits gwt-visualization.jar.
then in code:
runnable onloadcallback = new runnable() { @override public void run() { draw(); } }; visualizationutils.loadvisualizationapi(onloadcallback, corechart.package);
you don't need ajaxloader.
ajax gwt google-visualization
No comments:
Post a Comment