Search code examples
javascriptgraphd3.jsstacked-area-chartnvd3.js

NVD3 not dealing with large values


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.


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.