I can't find the flaw in the following d3 code:
//d3.tsv("dictionaries/dictionary-tsv.tsv",
// function(d) { return +d.frequency },
// function(error, rows) { console.log(rows);},
// function(d) { drawExample(data) }
// );
var data = [1,2,12,4,7];
drawExample(data);
function drawExample(frequency) {
var x = d3.scale.linear()
.domain([0, d3.max(frequency)])
.range([0, 420]);
d3.select(".chart")
.selectAll("div")
.data(frequency)
.enter().append("div")
.style("width", function(d) { return x(d) + "px"; })
.text(function(d) { return d; });
}
If you run as it is the bar chart is produced. If you comment var data and drawExample and uncomment the method to get external data from a tsv, it fails (althouth the firefox debugger shows that the data is loaded and no undefined var shows anywhere). Also the stackoverflow links:
"csv to array in d3.js" ,and "variable scope in d3 javascript"
does not seem to help. I am using d3.v3.min.js and my tsv file is the following:
word frequency
and 1
be 2
art 12
break 4
cat 7
I am sure that it is my mistake so any help would be greatly appreciated !