Search code examples
gwtgchart

gchart not appearing


i am using this simple example from GChart

      public void displayGChart(final ArrayList<ResultDTO> result){

        GChart c = new GChart();
        c.setChartTitle("<b>x<sup>2</sup> vs x</b>");
        c. setChartSize(150, 150);
        c. addCurve();
         for (int i = 0; i < 10; i++) 
             c.  getCurve().addPoint(i,i*i);
         c.getCurve().setLegendLabel("x<sup>2</sup>");
         c. getXAxis().setAxisLabel("x");
         c. getYAxis().setAxisLabel("x<sup>2</sup>");


    verticalPanel.add(c);
    verticalPanel.add(new Label("test"));
}

when i run the application ,I got NO errors , and i can see this "test" on my browser but nothing else , no chart is appearing..

i have added the jar and

            <inherits name='com.googlecode.gchart.GChart' />

Any Idea what could be the reason


Solution

  • Please call c.update(); after adding the chart to the panel, like this:

        verticalPanel.add(c);
        c.update();
        verticalPanel.add(new Label("test"));
    

    This is also described here: http://clientsidegchart.googlecode.com/svn/trunk/javadoc/com/googlecode/gchart/client/package-summary.html:

    No charts? These examples only define the chart. To actually display it, you must add and update it:

        // Use this typical GChart boilerplate to test out these examples:
        GChart gchart = new GChartExample00(); 
        RootPanel.get().add(gchart);
        gchart.update();