Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Invalid value for <rect> attribute width="NaN"

Tags:

d3.js

I'm completely new to d3. Ive have completed quite a few charts and examples from "Interactive Data Visualization for the Web" by Scott Murray and had very few problems. This is my first attempt at using a large data-set that is not contained within my code.

d3.csv("historical_weather.csv", function(error,data) {

    dataset = data.map(function(d){ 
        return [ parseInt(+d.cloudCover),parseInt(+ d.maxTemp) ];
    })

    console.log(dataset); 

    var svg = d3.select("body")
        .append("svg")
        .attr("height",500)
        .attr("width",500);

    d3.select("svg")
        .selectAll("rect")
        .data("dataset")
        .enter()
        .append("rect")
        .attr("height",50)
        .attr("width", function(d){return d.maxTemp*10;});

});

The data loads and is visible in the console as an array, I can see the expected values when digging into the array. However the console shows :

Error: Invalid value for attribute width="NaN"

like image 952
Banner Avatar asked Aug 16 '13 02:08

Banner


1 Answers

Seems you have a typo. The line that says .data("dataset") should instead be .data(dataset) with no quotation marks. I.e., you should be submitting the dataset variable, not a string containing its' name.

like image 77
Yony Avatar answered Sep 20 '22 10:09

Yony