简体   繁体   English

未捕获的错误:无效值0,0

[英]Uncaught Error: Invalid value in 0,0

I'm having a really weird issue while trying to visualize this scatter plot using the google visualization API. 我在尝试使用Google可视化API可视化此散点图时遇到一个非常奇怪的问题。

Basically, if I put the first data point as [0,0] everything will be fine, but if remove [0,0] as the first point, the chart won't produce. 基本上,如果我将第一个数据点设为[0,0],一切都会好起来,但是,如果删除[0,0]作为第一个点,则不会生成图表。 I checked the console and this is what it said: 我检查了控制台,这就是它的意思:

"Uncaught SyntaxError: Unexpected token < “未捕获的SyntaxError:意外令牌<
Uncaught Error: Invalid value in 0,0" 未捕获的错误:无效值0,0“

Why exactly does the first point need to be [0,0]? 为什么第一点确切需要为[0,0]?

<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Camera','Avg Rating'],
          [ {v:6000, f: 'Canon EOS-1Ds Mark III'}, 60],
          [ {v:5000, f: 'Canon EOS-1Ds Mark II'}, 50],
          [ {v:4000, f: 'Canon EOS-1D Mark IV'}, 40]
        ]);

        var options = {
          title: 'Breakdown of Camera Models by Price, Photo Rating and Brand',
          hAxis: {title: 'Price (USD)', minValue: 0, maxValue: 7500},
          vAxis: {title: 'Avg Rating (at peak)', minValue: 0, maxValue: 55},
          legend: 'none'          
        };
        var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="chart_div" style="width: 1000px; height: 1000px;"></div>
  </body>
</html>

The problem here is that the {v: value, f: 'formatted value'} syntax is not valid for use with the arrayToDataTable method (as documented here( https://developers.google.com/chart/interactive/docs/reference#google.visualization.arraytodatatable ) ). 这里的问题是{v:value,f:'formatted value'}语法不适用于arrayToDataTable方法(如此处所记录( https://developers.google.com/chart/interactive/docs/reference #google.visualization.arraytodatatable ))。 If you want to use that syntax, you will have to define your DataTable manually, and then use the #addRows method 如果要使用该语法,则必须手动定义DataTable,然后使用#addRows方法

Not sure why I had the error, but I found a way to get around it. 不知道为什么会出错,但是我找到了解决该错误的方法。 It started working when I used the DataTable constructor: 当我使用DataTable构造函数时,它开始工作:

var data = new google.visualization.DataTable();
                data.addColumn('number', 'Price');
                data.addColumn('number', 'Canon');
                data.addColumn('number', 'Nikon');
                data.addColumn('number', 'Other');
                data.addRows([
                  [{v:6000, f: 'Canon EOS-1Ds Mark III'}, 60  ,null  ,null],
                  [{v:5000, f: 'Canon EOS-1Ds Mark II'}, 50  ,null  ,null],

Instead of the arraytoDataTable constructor: 代替arraytoDataTable构造函数:

   var data = google.visualization.arrayToDataTable([
      ['Camera','Avg Rating'],
      [ {v:6000, f: 'Canon EOS-1Ds Mark III'}, 60],
      [ {v:5000, f: 'Canon EOS-1Ds Mark II'}, 50],
      [ {v:4000, f: 'Canon EOS-1D Mark IV'}, 40]
    ]);

Hope that helps anybody who also runs into this. 希望对任何遇到此问题的人有所帮助。

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

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