Basic Map
优质
小牛编辑
131浏览
2023-12-01
以下是基本地图的示例。
我们已经在Google Charts Configuration Syntax一章中看到了用于绘制图表的配置 。 现在,让我们看一个地图的例子。
配置 (Configurations)
我们使用Map类来显示基本的地图。
// map chart
Map chart = new Map();
例子 (Example)
HelloWorld.java
package cn.xnip.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.googlecode.gwt.charts.client.ChartLoader;
import com.googlecode.gwt.charts.client.ChartPackage;
import com.googlecode.gwt.charts.client.ColumnType;
import com.googlecode.gwt.charts.client.DataTable;
import com.googlecode.gwt.charts.client.map.Map;
import com.googlecode.gwt.charts.client.map.MapOptions;
public class HelloWorld implements EntryPoint {
private Map chart;
private void initialize() {
ChartLoader chartLoader = new ChartLoader(ChartPackage.MAP);
chartLoader.loadApi(new Runnable() {
public void run() {
// Create and attach the chart
chart = new Map();
RootPanel.get().add(chart);
draw();
}
});
}
private void draw() {
// Prepare the data
DataTable data = DataTable.create();
data.addColumn(ColumnType.STRING, "Country");
data.addColumn(ColumnType.STRING, "Population");
data.addRow("China", "China: 1,363,800,000");
data.addRow("India", "India: 1,242,620,000");
data.addRow("US", "US: 317,842,000");
data.addRow("Indonesia", "Indonesia: 247,424,598");
data.addRow("Brazil", "Brazil: 201,032,714");
data.addRow("Pakistan", "Pakistan: 186,134,000");
data.addRow("Nigeria", "Nigeria: 173,615,000");
data.addRow("Bangladesh", "Bangladesh: 152,518,015");
data.addRow("Russia", "Russia: 146,019,512");
data.addRow("Japan", "Japan: 127,120,000");
// Set options
MapOptions options = MapOptions.create();
options.setShowTip(true);
// Draw the chart
chart.draw(data,options);
chart.setWidth("400px");
chart.setHeight("400px");
}
public void onModuleLoad() {
initialize();
}
}
结果 (Result)
验证结果。