GWT Google Charts - Carte de base

Voici un exemple de carte de base.

Nous avons déjà vu les configurations utilisées pour dessiner un graphique dans le chapitre Syntaxe de configuration de Google Charts . Voyons maintenant un exemple de carte graphique.

Configurations

Nous avons utilisé Map classe pour afficher un graphique de base.

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

Exemple

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();
   }
}

Résultat

Vérifiez le résultat.