Search code examples
javascriptcsvd3.jsnvd3.jssparklines

NVD3 Sparkline not rendering correctly from CSV file


I'm trying to use NVD3 with d3.js to make a simple sparkline. I've successfully created several sparklines with .csv data, but when I tried to use a different data set, it gave a very strange looking sparkline. See here. If I change the first data value from 92 to 0, it successfully shows the sparkline.

Is this a bug in NVD3 or am I doing something wrong?


Solution

  • The problem was that the y values were strings. I changed

    monthlyData.push({x: data[i].Month, y: data[i].Data});
    

    to

    monthlyData.push({x: data[i].Month, y: +data[i].Data});
    

    so that the y value becomes a number. Here's the updated version.