Question

I keep getting this error:

Uncaught TypeError: Cannot call method 'map' of undefined

When running this code:

        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;
    });
Was it helpful?

Solution

Problem is test_data is formatted incorrectly. It should be wrapped in an array containing an object which defines the fields "keys" and "values"

    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
                },
            ]
        }
    ];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top