我加了你的新代码,但会有error, 说data is not defined.我不知道哪里做错。
d3.csv("data.csv", type, function(data){
console.log(data);
});
function type(d){
d.population = +d.population;
return d;
}
var bar_width = 50,
bar_padding = 10,
svg_width = (bar_width + bar_padding) * data.length, <-------'data is not defined'
svg_height=500;
兄弟 这样才对
d3.csv("data.csv", type, function(data){ console.log(data); function type(d){ d.population = +d.population; return d; } var bar_width = 50, bar_padding = 10, svg_width = (bar_width + bar_padding) * data.length, svg_height=500; });