【问题标题】:Error when rendering nvd3 bar graph渲染 nvd3 条形图时出错
【发布时间】:2014-02-28 17:21:57
【问题描述】:

我不断收到此错误:

Uncaught TypeError: Cannot call method 'map' of undefined

运行此代码时:

        var testdata = [
                {
                    label: "One",
                    x: 5,
                    y: 10
                },
                {
                    label: "2",
                    x: 6,
                    y: 15
                },
                {
                    label: "3",
                    x: 5,
                    y: 25
                },
                {
                    label: "4",
                    x: 10,
                    y: 0
                }
    ];

    nv.addGraph(function () {
        var width = nv.utils.windowSize().width - 40,
            height = nv.utils.windowSize().height / 2 - 40;

        var chart = nv.models.multiBar()
            .stacked(true)
            .width(width)
            .height(height);

        d3.select("#lschart svg")
            .datum(testdata)
            .transition().duration(1200)
            .attr('width', width)
            .attr('height', height)
            .call(chart);

        return chart;
    });

【问题讨论】:

    标签: charts d3.js nvd3.js


    【解决方案1】:

    问题是 test_data 的格式不正确。它应该被包装在一个包含定义字段“键”和“值”的对象的数组中

        var testdata = [
            {
                keys: "returns",
    
                values: [
                    {
                        label: "One",
                        x: 5,
                        y: 10
                    },
                    {
                        label: "2",
                        x: 6,
                        y: 15
                    },
                    {
                        label: "3",
                        x: 5,
                        y: 25
                    },
                    {
                        label: "4",
                        x: 10,
                        y: 0
                    },
                ]
            }
        ];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多