0
我正在嘗試使用Google Visualization將交互式圖表整合到GWT應用程序中。我不想連接到Google App引擎。我還想使用GWT API,而不是在我的代碼中嵌入javaScript。我試圖在gwt-google-apis中遵循示例SimpleViz和HelloAjaxLoader,但圖表無法加載。我已將ajaxloader和可視化jar添加到我的類路徑中,並在gwt.xml中繼承。在以下代碼中,將顯示「onModuleLoad」中的警報,但不是「正在運行」。如何在GWT和AjaxLoader中使用Google可視化圖表
我的代碼:
public class SimpleViz implements EntryPoint {
private VerticalPanel container;
private ImagePieChart chart;
public void onModuleLoad() {
Window.alert("In onModuleLoad");
container = new VerticalPanel();
RootPanel.get().add(container);
container.getElement().getStyle().setPropertyPx("margin", 10);
container.setSpacing(10);
container.add(new Label("Pie Chart Example"));
AjaxLoader.init();
AjaxLoader.loadApi("visualization", "1", new Runnable() {
public void run() {
Window.alert("In run");
chart=new ImagePieChart();
container.add(chart);
draw();
}
}, null);
}
private void draw() {
// Prepare the data
DataTable dataTable = DataTable.create();
dataTable.addColumn(ColumnType.STRING, "Task");
dataTable.addColumn(ColumnType.NUMBER, "Hours per Day");
dataTable.addRows(5);
dataTable.setValue(0, 0, "Work");
dataTable.setValue(0, 1, 11);
dataTable.setValue(1, 0, "Sleep");
dataTable.setValue(1, 1, 7);
dataTable.setValue(2, 0, "Watch TV");
dataTable.setValue(2, 1, 3);
dataTable.setValue(3, 0, "Eat");
dataTable.setValue(3, 1, 2);
dataTable.setValue(4, 0, "Commute");
dataTable.setValue(4, 1, 1);
// Set options
ImagePieChart.Options options = ImagePieChart.Options.create();
options.setBackgroundColor("#f0f0f0");
options.setIs3D(false);
options.setTitle("So, how was your day?");
// Draw the chart
chart.draw(dataTable, options);
}
}
作爲後續問題,是這些庫的電流和良好的維護或者我應該尋找不同的解決方案?
謝謝。當我連接到互聯網時使用VisualizationUtils。在沒有連接到Google網站的情況下,是否有任何方法使用可視化? – Alicia 2014-10-06 15:34:58
請參閱:https://developers.google.com/chart/interactive/faq#offline和同一列表中的下一個問題。 – 2014-10-06 16:31:50
再次感謝。瞭解。 – Alicia 2014-10-06 23:01:52