Googlecharts-map-basic

提供:Dev Guides
移動先:案内検索

Google Chart-基本的な地図

以下は、基本的なマップの例です。 link:/googlecharts/googlecharts_configuration_syntax [Googleグラフの構成構文]の章で、このグラフを描画するために使用される構成を見てきました。 それでは、完全な例を見てみましょう。

構成

*Map* クラスを使用して、マップベースのチャートを表示しました。
//Map chart
var chart = new google.visualization.Map(document.getElementById('container'));

googlecharts_map_basic

<html>
   <head>
      <title>Google Charts Tutorial</title>
      <script type = "text/javascript" src = "https://www.gstatic.com/charts/loader.js">
      </script>
      <script type = "text/javascript" src = "https://www.google.com/jsapi"></script>
      <script type = "text/javascript">
         google.charts.load('current', {packages: ['map']});
      </script>
   </head>

   <body>
      <div id = "container" style = "width: 550px; height: 400px; margin: 0 auto">
      </div>
      <script language = "JavaScript">
         function drawChart() {
           //Define the chart to be drawn.
            var data = google.visualization.arrayToDataTable([
               ['Country', 'Population'],
               ['China', 'China: 1,363,800,000'],
               ['India', 'India: 1,242,620,000'],
               ['US', 'US: 317,842,000'],
               ['Indonesia', 'Indonesia: 247,424,598'],
               ['Brazil', 'Brazil: 201,032,714'],
               ['Pakistan', 'Pakistan: 186,134,000'],
               ['Nigeria', 'Nigeria: 173,615,000'],
               ['Bangladesh', 'Bangladesh: 152,518,015'],
               ['Russia', 'Russia: 146,019,512'],
               ['Japan', 'Japan: 127,120,000']
            ]);

           //Set chart options
            var options = {showTip: true};

           //Instantiate and draw the chart.
            var chart = new google.visualization.Map(document.getElementById('container'));
            chart.draw(data, options);
         }
         google.charts.setOnLoadCallback(drawChart);
      </script>
   </body>
</html>

結果

結果を確認します。