Question

I have a graph implemented in NVD3, and I'm having serious trouble with it. NVD3 seems unable to handle datasets which contain large values. The graph is located here: http://brad.kizer.com.ng/. The code for the graph is as so:

nv.addGraph(function() {
    // Get maximum and minimum Y values
    var minY = 2 >> 30,
        maxY = 0;

    data.forEach(function (d) {
        d.values.forEach(function (s) {
            minY = Math.min(minY, s.y);
            maxY = Math.max(maxY, s.y);
        });
    });

    var chart = nv.models.stackedArea()
        .forceY([0, 20])
        .height($(container).closest('.chart').height())
        .width($(container).closest('.chart').width());

    (Object.prototype.toString.call(data) === '[object Array]') || (data = [data]);

      d3.select(container)
          .attr('width', $(container).closest('.chart').width())
          .attr('height', 250)
          .datum(data)
        .transition().duration(500)
          .call(chart);

    nv.utils.windowResize(chart.update);
    return chart;
});

I will appreciate any help so much, as this has kept me scratching my head for days.

Was it helpful?

Solution

Solved my problem. The issue was that the data provided for the Y-axis was strings, which made supposedly number addition become string concatenation:

"123" + "902" + "384" + "382" == "123902384382"; // (instead of 1791)

What I did was walk through the data and convert the strings to numbers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top