2017-02-10 42 views
1

喜IM與googleCharts https://developers.google.com/chart/interactive/docs/gallery/geochart 工作,我需要設置地理散列成積列,但我嘗試在目前所行的工作 經度和緯度,其作品谷歌圖表隨着地理散列

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> 
    <script type="text/javascript" src="<?php echo base_url();?>assets/js/script.js"></script> 
    <script type="text/javascript"> 
    google.charts.load('upcoming', {'packages': ['geochart']}); 
    google.charts.setOnLoadCallback(drawMarkersMap); 

     function drawMarkersMap() { 
     var data = new google.visualization.DataTable(); 
     data.addColumn('number', 'Latitude'); 
     data.addColumn('number', 'Longitude'); 
     data.addColumn('string', 'Label'); 
     data.addColumn('number', 'Value 1'); 
     data.addColumn('number', 'Value 2'); 

     data.addRows([ 
      [-22.764042, -43.39921, 'Foo', 2.86, 4], 
      [-22.755635, -43.460325, 'Bar', 5, 2], 
      [-22.912897, -43.200295, 'Baz', 0.50, 1], 
      [-22.805776, -43.37292, 'Cad', 6.67, 2], 
      [-23.532905, -46.63952, 'Qud', 33.33, 5] 
     ]); 
     var chart = new google.visualization.GeoChart(document.getElementById('chart_div')); 
    chart.draw(data, { 
     width: 600, 
     region: 'BR',//rgiomn 
     colorAxis: {colors: ['green', 'blue']} //color de transicion 


    }); 

    }; 
</script> 

但如果我嘗試用地理散列,告訴我這個錯誤控制檯:

drawMarkersMap — cargamapa:72ReferenceError: Can't find variable: gbsuv

我瓦爾

data.addRows([ 
     ['gbsuv', 'Foo', 2.86, 4], 
     ['gbsuv', 'Bar', 5, 2], 
     ['gbtst' 'Baz', 0.50, 1], 

    ]); 

回答

2

請分享varaibles值...

gbsuv, gbtst, gbtse 

,如果他們是陣列([]),然後再嘗試......

data.addRows([ 
    [gbsuv[0], gbsuv[1], 'Foo', 2.86, 4], 
    [gbsuv[0], gbsuv[1], 'Bar', 5, 2], 
    [gbtst[0], gbtst[1], 'Baz', 0.50, 1], 
    [gbtse[0], gbtse[1], 'Cad', 6.67, 2] 
]); 

編輯

地圖 v >Geohash.decode(geohash)
會 - isualization不支持地理散列

Two data formats are supported:

1.Lat-Long pairs - The first two columns should be numbers designating the latitude and longitude, respectively. An optional third column holds a string that describes the location specified in the first two columns.

2.String address - The first column should be a string that contains an address. This address should be as complete as you can make it. An optional second column holds a string that describes the location in the first column. String addresses load more slowly, especially when you have more than 10 addresses.

但是,你可以使用庫,如...

latlon-geohash.js

調用該函數解碼地理散列返回屬性爲latlon的對象

var gbsuv = Geohash.decode('gbsuv'); 

data.addRows([ 
    [gbsuv.lat, gbsuv.lon, 'Foo', 2.86, 4], 
    ... 
]); 
+0

變量值與字符串值相同 –

+0

請參閱上面的__EDIT__ ... – WhiteHat