GWT Google Charts - Basic Map Chart


Advertisements

Following is an example of a basic Map Chart.

We have already seen the configurations used to draw a chart in Google Charts Configuration Syntax chapter. Now, let us see an example of a Map Chart.

Configurations

We've used Map class to show a basic Map Chart.

// map chart
Map chart = new Map();

Example

HelloWorld.java

package com.tutorialspoint.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

Verify the result.

Basic Map Chart
gwt_googlecharts_maps.htm
Advertisements