1

I want to use the Visualization javascript API from Google in my GWT project. I am using the JSNI methods but it didn't work :

private native void drawChart() /*-{

  drawChart = function() {

    // Create the data table.
    var data = new $wnd.google.visualization.DataTable();
    $wnd.data.addColumn('string', 'Topping');
    $wnd.data.addColumn('number', 'Slices');
    $wnd.data.addRows([
      ['Mushrooms', 3],
      ['Onions', 1],
      ['Olives', 1],
      ['Zucchini', 1],
      ['Pepperoni', 2]
    ]);

    // Set chart options
    var options = {'title':'How Much Pizza I Ate Last Night',
                   'width':400,
                   'height':300};

    // Instantiate and draw our chart, passing in some options.
    var chart = new $wnd.google.visualization.PieChart($doc.getElementById('chart_div'));
    $wnd.chart.draw(data, options);
  }
  $wnd.google.load('visualization', '1.0', {'packages':['corechart']});
  $wnd.google.setOnLoadCallback(drawChart);
}-*/;

I know that there's a GWT wrapper for this API but the javascript Visualisation API contains more Chart types and more features; for example I want to use ChartEditor in my GWT Project : like here

Does anyone have an example or an idea to make it work ?

enrybo
  • 1,787
  • 1
  • 12
  • 20

1 Answers1

0

Make sure you have

<script type="text/javascript" src="https://www.google.com/jsapi"></script>

in your HTML and

google.load('visualization', '1.0', {'packages':['corechart']});

somewhere to actually load the api.

Also don't try to use the API before it's loaded. Use this callback:

// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
enrybo
  • 1,787
  • 1
  • 12
  • 20