Google Visualization柱形图错误

时间:2018-02-14 08:02:42

标签: charts google-visualization

我尝试使用Google Visualization的柱形图显示一些数据。

这是我正在使用的html / javascript:     

<script type="text/javascript">
   google.charts.load('current', {'packages':['bar']});
   google.charts.setOnLoadCallback(drawChart);

   function drawChart() {
     var data = google.visualization.arrayToDataTable([
       ['Rating', 'Form 1', 'Form 2'],
       ['Very Poor', 1000, 400],
       ['Poor', 1170, 460],
       ['Average', 660, 1120],
       ['Good', 1030, 540]
       ['Very Good', 1030, 540]

     ]);

     var options = {
       height: 400,                  
     };

     var chart = new google.charts.Bar(document.getElementById('{{ question.0.name }}'));

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

当我去加载页面时,我收到此错误:

jsapi_compiled_default_module.js:85 Uncaught (in promise) Error: Invalid row type for row 3
    at gvjs_Fba (jsapi_compiled_default_module.js:85)
    at Object.gvjs_8m [as arrayToDataTable] (jsapi_compiled_default_module.js:86)
    at drawChart ((index):57)
    at <anonymous>

这是指这一行(至少我认为是这样,当我点击错误时,此行在检查工具中变为黄色):

var data = google.visualization.arrayToDataTable([

1 个答案:

答案 0 :(得分:0)

我忘记了列表中的逗号

 var data = google.visualization.arrayToDataTable([
   ['Rating', 'Form 1', 'Form 2'],
   ['Very Poor', 1000, 400],
   ['Poor', 1170, 460],
   ['Average', 660, 1120],
   ['Good', 1030, 540], <----- NEEDED THIS
   ['Very Good', 1030, 540]

 ]);