我正在尝试在位于我网页中间的 HTML 面板中运行来自谷歌图表示例的测试图表。我想对图表进行很多自定义,这就是为什么我不想使用从谷歌图表派生的任何类型的 api。我想在 HTMLPanel 中简单地运行 javascript。这是我尝试过的。
public class TwitterTimeSeries implements EntryPoint
{
public void onModuleLoad() {
Element script2 = DOM.createElement("script");
DOM.setElementAttribute(script2,"language","text/javascript");
DOM.setElementAttribute(script2,"src","https://www.google.com/jsapi");
Element script = DOM.createElement("script");
DOM.setElementAttribute(script,"language","text/javascript");
script.setInnerText("google.load('visualization', '1.0', {'packages' ['corechart']});"
+ "google.setOnLoadCallback(drawChart);"
+ "function drawChart() {"
+ "var data = google.visualization.arrayToDataTable([['Year', 'Sales', 'Expenses'], ['2004', 1000, 400], ['2005', 1170, 460], ['2006', 660, 1120], ['2007', 1030, 540]]);"
+ "var options = {title: 'Company Performance'};"
+ "var chart = new google.visualization.LineChart(document.getElementById('chart_div'));"
+ "chart.draw(data, options); }"
);
HTMLPanel html = new HTMLPanel("<div id=\"chart_div\"></div>");
RootPanel.get().add(html);
DOM.appendChild(DOM.getElementById("chart_div"),script);
}
};
谁能指出我正确的方向?