1

我想在我的 GWT 项目中使用 Google 的 Visualization javascript API。我正在使用 JSNI 方法,但它不起作用:

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);
}-*/;

我知道这个 API 有一个 GWT 包装器,但是 javascript Visualization API 包含更多图表类型和更多功能;例如我想ChartEditor在我的 GWT 项目中使用:就像这里

有没有人有一个例子或想法让它发挥作用?

4

1 回答 1

0

确保你有

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

在您的 HTML 和

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

在某个地方实际加载 api。

也不要在加载之前尝试使用 API。使用此回调:

// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
于 2013-01-29T16:32:39.237 回答