谷歌折线图显示销售报告小时

时间:2017-02-20 07:05:27

标签: charts google-visualization

如何绘制谷歌折线图显示销售报告小时明智,我在谷歌搜索,我找到了一个折线图解决方案,但在那它采取了两个项目,但我需要每小时销售线图表..我尝试删除第二个数量,但我收到错误。我试过下面的代码

<html>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>     
</html>
<script>
google.charts.load('current', {packages: ['linechart', 'line']});
google.charts.setOnLoadCallback(drawCurveTypes);

function drawCurveTypes() {
  var data = new google.visualization.DataTable();
  data.addColumn('number', 'X');
  data.addColumn('number', 'Dogs');

  data.addRows([
    [0, 0],    [1, 10],   [2, 23],  [3, 17 ],   [4, 18],  [5, 9],
    [6, 11],   [7, 27],  [8, 33],  [9, 40],  [10, 32], [11, 35,
    [12, 30], [13, 40], [14, 42], [15, 47], [16, 44], [17, 48],
    [18, 52], [19, 54], [20, 42]
  ]);

  var options = {
    hAxis: {
      title: 'Time'
    },
    vAxis: {
      title: 'Popularity'
    },
    series: {
      1: {curveType: 'function'}
    }
  };

  var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
  chart.draw(data, options);
}
</script>

当我尝试使用上面的代码时,我得到了下面的错误 data.addRows末尾的未捕获的SyntaxError:意外的标记。请有人帮助我。提前谢谢。

1 个答案:

答案 0 :(得分:0)

问题出在数据......

其中一个数组值上缺少括号......

data.addRows([
  [0, 0],    [1, 10],   [2, 23],  [3, 17 ],   [4, 18],  [5, 9],
  [6, 11],   [7, 27],  [8, 33],  [9, 40],  [10, 32], [11, 35,   // <-- missing bracket
  [12, 30], [13, 40], [14, 42], [15, 47], [16, 44], [17, 48],
  [18, 52], [19, 54], [20, 42]
]);

纠正......

data.addRows([
  [0, 0],    [1, 10],   [2, 23],  [3, 17 ],   [4, 18],  [5, 9],
  [6, 11],   [7, 27],  [8, 33],  [9, 40],  [10, 32], [11, 35],   // <-- correct
  [12, 30], [13, 40], [14, 42], [15, 47], [16, 44], [17, 48],
  [18, 52], [19, 54], [20, 42]
]);

请参阅以下工作代码段...

&#13;
&#13;
google.charts.load('current', {packages: ['corechart']});
google.charts.setOnLoadCallback(drawCurveTypes);

function drawCurveTypes() {
  var data = new google.visualization.DataTable();
  data.addColumn('number', 'X');
  data.addColumn('number', 'Dogs');

  data.addRows([
    [0, 0],    [1, 10],   [2, 23],  [3, 17 ],   [4, 18],  [5, 9],
    [6, 11],   [7, 27],  [8, 33],  [9, 40],  [10, 32], [11, 35],
    [12, 30], [13, 40], [14, 42], [15, 47], [16, 44], [17, 48],
    [18, 52], [19, 54], [20, 42]
  ]);

  var options = {
    hAxis: {
      title: 'Time'
    },
    vAxis: {
      title: 'Popularity'
    },
    series: {
      1: {curveType: 'function'}
    }
  };

  var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
  chart.draw(data, options);
}
&#13;
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
&#13;
&#13;
&#13;

注意:只需要'corechart'个包...

google.charts.load('current', {packages: ['corechart']});