0

我的数据表:

Country                        Types of sales   Total sales($)  Name                                State       
United states of America           chemicals    12662871    Obama                                GA 
United states of America           electronics  20145684    Romney                               ON 
United states of America           textiles     22458756    Gliton                               MB 
United states of America           automobiles  34235684    Andrew Jackson                       BC 
United states of America           chemicals    19438333    James Madison                       AB  

而不是给状态列,如果我给名称列,该名称也绘制在地理图表中,就像在附件文件中一样。

仅当 displayMode 为 Marker 时才会发生这种情况。

Javascript代码:

<html>

<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<title>Google Visualization API Sample</title>

<script type="text/javascript" src="http://www.google.com/jsapi"></script>

<script type="text/javascript">

    function drawMarkersMap() {

        var data = google.visualization.arrayToDataTable([

        ['Name', 'Total Sales'],
        ['Romney', 20145684],
        ['Obama', 12662871],
        ['Gliton', 22458756],
        ['Andrew Jackson', 34235684],
        ['James Madison', 19438333]
    ]);

        var options = {

            region: 'US',
            resolution: 'provinces',
            displayMode:'markers',
            width: 400,
            height: 400,
            colorAxis: {
                //values: [-1, 0, 1],
                colors: ['#FF0000']
            }
        };

        var geochart = new google.visualization.GeoChart(document.getElementById('visualization'));

        geochart.draw(data, options);

        google.visualization.events.addListener(geochart, 'select', function (eventOption) {

            var item = geochart.getSelection();


            var value = data.getValue(item[0].row, 1);

            alert(value);
        });
    }

    google.load('visualization', '1', { packages: ['geochart'] });

    google.setOnLoadCallback(drawMarkersMap);


</script>

</head>

<body style="font-family: Arial;border: 0 none;">

<div id="visualization"></div>

</body>

</html>

请提供解决方案来解决它。

提前致谢。

4

1 回答 1

0

假设您想将每个人显示为负责一个州,他们的名字显示在悬停上,如下所示:

地图样本

您可以使用这样的代码来实现这一点,使用{v:'value',f:'format'}符号:

function drawVisualization() {
  var data = new google.visualization.DataTable();
  data.addColumn('string','Name');
  data.addColumn('number','Sales');
  data.addRows([
    [{v:'MA',f:'Romney'}, 20145684],
    [{v:'IL',f:'Obama'}, 12662871],
    [{v:'NH',f:'Gliton'}, 22458756],
    [{v:'TN',f:'Andrew Jackson'}, 34235684],
    [{v:'VA',f:'James Madison'}, 19438333]
  ]);

  var options = {
    region: 'US',
    resolution: 'provinces',
    width: 600,
    height: 400
  };

var chart = new google.visualization.GeoChart(document.getElementById('visualization')); chart.draw(数据,选项);};

于 2013-07-17T23:59:10.857 回答