简体   繁体   English

Google图表未显示Axis?

[英]Google chart not showing Axis?

I've been messing around with Google Geo Chart this morning and while I've got it working for the most part, it does not show the axis at the bottom. 今天早上,我一直在使用Google地理图表,虽然大部分时间都在使用它,但它并没有在底部显示轴。 It also does not show the country in the tooltip on hover. 它也没有在悬停工具提示中显示国家。

The code I'm using is: 我使用的代码是:

<script type="text/javascript">
    function mapMe() {
      google.charts.load('upcoming', {'packages':['geochart']});
      google.charts.setOnLoadCallback(drawRegionsMap);

      function drawRegionsMap() {
        arr = myParse();        
        var data = google.visualization.arrayToDataTable(arr);  

        var options = {colorAxis: {colors: ['#f5f5f5','#267114']}};
        var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));

        chart.draw(data, options);
      }
    }
</script>
<div class='container'>
    <div id="regions_div" style="width: 900px; height: 500px;"></div>
        <br><br><br><textarea rows="4" cols="50" id="testArea"></textarea>
        <button onclick='mapMe()'>
</div>

..and the function called for the array is: ..并且为数组调用的函数是:

function myParse() {
    var data = $('#testArea').val();
    var rows = data.split("\n");
    var result = [];
    var col = [];
    for (var r in rows) {
        row = rows[r].split("\t");
        result.push(row);
    }
    return result;
}

The result: 结果: 截图

The data I am entering is copied from Excel and pasted into a text area. 我输入的数据是从Excel复制并粘贴到文本区域中的。 It looks like: 看起来像:

|Country|Number|
|Russia |1     |
..etc

Am I missing something silly? 我想念一些愚蠢的东西吗? Just can't puzzle it out. 只是无法解决。 Any help is much appreciated! 任何帮助深表感谢!

Changed my approach and got it working, albeit not in the way I originally intended: 改变了我的方法并使它起作用,尽管不是我最初打算的那样:

    function mapMe() {

        google.charts.load('upcoming', {'packages':['geochart']});
        google.charts.setOnLoadCallback(drawRegionsMap);

        function drawRegionsMap() {

            var data_table = new google.visualization.DataTable();

            //NEED TO UPDATE THIS TO CHECK DATA TYPE OF FIRST ROW AND AUTO OUTPUT COLUMN HEADERS
            data_table.addColumn({"type": "string","label": "Country"});
            data_table.addColumn({"type": "number","label": "Volume"});

            var datas = $('#testArea').val();
            var rows = datas.split("\n");

            for (var r = 1; r < rows.length; r++) {
                row = rows[r].split("\t");
                data_table.addRow([{v: row[0]}, {v: parseInt(row[1])}]);
            }

            var options = {colorAxis: {colors: ['#f5f5f5','#267114']},  legend: {textStyle: {color: 'blue', fontSize: 16}}};
            var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));


            chart.draw(data_table, options);
        }
    }

Rather than try to pass an array in, I'm looping through and using the addRow command as I go. 我没有遍历传递数组,而是在遍历并使用addRow命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM