• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

GWT Viz API application using server data to render charts

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Is there any way to fetch server side data and render it to the
charting components in a GWT-VIZ API enabled app? I tried something
unsure from my side but it did not worked for me.
Scenario: Display some server data on a column chart.
This is what I tried :
<code>
public class ChartPOC implements EntryPoint{


public ArrayList<PaymentObject> plciObj = new
ArrayList<PaymentObject>();
public ColumnChart columnChart ;
public DataTable data ;


public void onModuleLoad() {
Runnable onLoadCallback = new Runnable() {
public void run() { // this is my debug point


ColumnChart.Options options = ColumnChart.Options.create();
ColumnChart tempColumnChart = new ColumnChart(createColTable(),
createColumnOptions(options)); // this creates a column chart
columnChart = tempColumnChart;// set it to the class level chart
// Set up the callback object.
}
};
// Load the visualization api, passing the onLoadCallback to be
called
// when loading is done.
VisualizationUtils.loadVisualizationApi(onLoadCallback,
ColumnChart.PACKAGE);
RootPanel rp = RootPanel.get("sampleCharting");
//rp.add(new HTML("hello"));
rp.add(tempColumnChart);


}


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 AbstractDataTable createColTable() {
PLCIServiceAsync service = GWT.create(PLCIService.class);// This is
an Async interface
data = DataTable.create();
data.addColumn(ColumnType.STRING, "PLCI");
data.addColumn(ColumnType.NUMBER, "Payment");
// data.addColumn(ColumnType.NUMBER, "PLCI");
data.addRows(3);


AsyncCallback<ArrayList<PaymentPLCIObject>> callback = new
AsyncCallback<ArrayList<PaymentPLCIObject>>() {// implement
AsyncCallback methods
public void onFailure(Throwable caught) {
// TODO: Do something with errors.
}


public void onSuccess(ArrayList<PaymentPLCIObject> result) {
updateTable(result);// update the DataTable with server
response
}
};
service.getPLCIs(callback);// call the server side service
class's method
return data;
}


private void updateTable(ArrayList<PaymentPLCIObject> result){
for(int index=0; index<result.size(); index++){
PaymentPLCIObject obj = (PaymentPLCIObject)result.get(index);
data.setValue(index, 0,obj.getPlciCode());
data.setValue(index, 1, obj.getPayment());
columnChart.draw(data);
}
}



}


</code>

when I try to debug the app, the app fails when reaches "public void
run() {".
Any help would be appreciated


Thanks
Ankit


 
I knew that guy would be trouble! Thanks tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic