vAx是奇怪的数字顺序

时间:2016-03-04 21:17:11

标签: google-visualization

任何人都知道为什么我的谷歌图表会以如此奇怪的顺序显示左边的数字?

以下是问题的图片:

enter image description here

以下是我使用的代码:

<script type="text/javascript">
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Ad', 'Views', 'Conversions', 'Appointments'],
          ["green", "9", "2", "2"],["logo", "18", "8", "1"],["maps", "8", "2", "0"],["resign", "14", "9", "1"],["scanimage", "1", "0", "0"],            ]);

        var options = {
          chart: {
            title: ''
          }
        };

        var chart = new google.charts.Bar(document.getElementById('ad_chart'));

        chart.draw(data, options);
      }
</script>

1 个答案:

答案 0 :(得分:1)

轴类型由数据中的值确定。

字符串值产生离散轴,数字连续 ...

google.charts.load('44', {'packages': ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {
    // Number data (Continuous)
    var data0 = google.visualization.arrayToDataTable([
      ['Ad', 'Views', 'Conversions', 'Appointments'],
      ["green", 9, 2, 2],
      ["logo", 18, 8, 1],
      ["maps", 8, 2, 0],
      ["resign", 14, 9, 1],
      ["scanimage", 1, 0, 0]
    ]);

    // String data (Discrete)
    var data1 = google.visualization.arrayToDataTable([
      ['Ad', 'Views', 'Conversions', 'Appointments'],
      ["green", "9", "2", "2"],
      ["logo", "18", "8", "1"],
      ["maps", "8", "2", "0"],
      ["resign", "14", "9", "1"],
      ["scanimage", "1", "0", "0"]
    ]);

    var options = {
      chart: {
        title: ''
      }
    };

    var chart0 = new google.charts.Bar(document.getElementById('ad_chart0'));
    chart0.draw(data0, options);

    var chart1 = new google.charts.Bar(document.getElementById('ad_chart1'));
    chart1.draw(data1, options);
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="ad_chart0"></div>
<div id="ad_chart1"></div>