给定的行大小不同于3;谷歌图表

"Row given with size different than 3" Google Charts

本文关键字:谷歌 不同于      更新时间:2023-09-26

我在一个名为Klipfolio的系统中使用谷歌图表。我已经修修补补好几天了。好奇其他人是否也这么做过。这个问题并不是Kipfolio独有的,但我认为一点背景知识可能会大有帮助。

这是代码:

var _component = this;
var _dataModel = this.dataModel;
var thearray = $.map(_dataModel, function(value, index) {
 return [value];
});
var thearrays = ('['+thearray.toString()+']');
var datadone = (JSON.parse(thearrays));
console.table(datadone);
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'From');
data.addColumn('string', 'To');
data.addColumn('number', 'Weight');
data.addRows([datadone]);
    // Sets chart options.
    var options = {
    sankey: {
        iterations: 700,
        node: {
            label: {
                fontName: 'Arial',
                fontSize: 12,
                color: 'rgb(74,74,74)',
                bold: true,
                italic: false
            },
            interactivity: true, // Allows you to select nodes.
            labelPadding: 3, // Horizontal distance between the label and the node.
            nodePadding: 20, // Vertical distance between nodes.
            width: 10, // Thickness of the node.
            colors: [
                'rgb(82,144,233)', // Custom color palette for sankey nodes.
            'rgb(113,179,124)', // Nodes will cycle through this palette
            'rgb(206,226,55)', // giving each node its own color.
            'rgb(239,209,64)',
                'rgb(236,147,47)',
                'rgb(225,77,87)',
                'rgb(150,89,148)',
                'rgb(157,121,82)',
                'rgb(154,146,137)']
        }
    }

};
    // Instantiates and draws our chart, passing in some options.
    var chart = new google.visualization.Sankey(document.getElementById('sankey_basic'));
    chart.draw(data, options);
  }

_dataModel变量在控制台输出。表如下:https://i.stack.imgur.com/DDudd.jpg.

数组变量在控制台中输出。表格如下:https://i.stack.imgur.com/73o76.jpg

当图表呈现时,它抛出错误:

未捕获的错误:行给定的大小不同于3(表中的列数)

我应该采取什么其他步骤来消除这个错误吗?我是使用javascript和对象/数组的新手。我看到thearray变量有4列出现,但这是问题吗?

看起来我的问题是在数据上添加括号。addRows函数。所以不是:

data.addRows([datadone]);

没有生成,我用:

代替
data.addRows(datadone);

感谢Henrik为我指出查看数据源。一旦我验证了地层,我就能够识别问题并修复它。图表现在看起来很棒!