Hi,
Is there any way to fetch server side data and render it to the
charting components in a GWT-VIZ API enabled app? In would be perfect
if someone can share some code examples of the rendering a chart
component with server data.
This is what I tried :
<code>
public DataTable data;
public boolean returnFlag = false;
public void onModuleLoad() {
/*Runnable onLoadCallback = new Runnable() {
public void run() {
ColumnChart.Options options =
ColumnChart.Options.create();
ColumnChart tempColumnChart = new
ColumnChart(data,
createColumnOptions(options));
//columnChart = tempColumnChart;
// Set up the callback object.
RootPanel rp = RootPanel.get("sampleCharting");
rp.add(tempColumnChart);
}
}; */
PLCIServiceAsync service = GWT.create(PLCIService.class);
AsyncCallback<ArrayList<PaymentPLCIObject>> callback = new
AsyncCallback<ArrayList<PaymentPLCIObject>>() {
public void onFailure(Throwable caught) {
int i = 0;
Window.alert("Server request failed!!");
}
public void onSuccess(ArrayList<PaymentPLCIObject>
result) {
// Window.alert("Server request successful!!");
updateTable(result);
returnFlag = true;
}
};
service.getPLCIs(callback);
// Load the visualization api, passing the onLoadCallback to be
called
// when loading is done.
//VisualizationUtils.loadVisualizationApi(onLoadCallback,
ColumnChart.PACKAGE);
}
private ColumnChart.Options createColumnOptions(ColumnChart.Options
options) {
//ColumnChart.Options options = ColumnChart.Options.create();
options.setWidth(600);
options.setHeight(400);
options.setColors("#F778A1", "#D16587");
options.setTitle("Earning Analysis");
options.setLegend(LegendPosition.BOTTOM);
options.setShowCategories(true);
options.setTitleX("PLCI");
options.setTitleY("Amount");
options.setTitle("COLUMN CHART WIDGET");
return options;
}
private void updateTable(ArrayList<PaymentPLCIObject> result){
DataTable dataTbl = DataTable.create();
dataTbl.addColumn(ColumnType.STRING, "PLCI");
dataTbl.addColumn(ColumnType.NUMBER, "Payment");
dataTbl.addRows(3);
for(int index=0; index<result.size(); index++){
PaymentPLCIObject obj =
(PaymentPLCIObject)result.get(index);
dataTbl.setValue(index, 0,obj.getPlciCode());
dataTbl.setValue(index, 1, obj.getPayment());
}
Runnable onLoadCallback = new Runnable() {
public void run() {
ColumnChart.Options options =
ColumnChart.Options.create();
ColumnChart tempColumnChart = new
ColumnChart(data,
createColumnOptions(options));
//columnChart = tempColumnChart;
// Set up the callback object.
RootPanel rp = RootPanel.get("sampleCharting");
rp.add(tempColumnChart);
}
};
data = dataTbl;
VisualizationUtils.loadVisualizationApi(onLoadCallback,
ColumnChart.PACKAGE);
}
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.