当我执行此代码时,我将收到错误,此错误为:Error
我对d3.stack()函数并不熟悉,所以我不知道如何调试它。这个错误有解决方法吗?
这是filtered_data:filtered_data的console.log()。每个对象都由纽约的五个行政区组成。
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
d3.csv("Air_Quality.csv", function (airquality_data) {
var variabelen = ["PM2.5-Attributable Deaths ", "O3-Attributable Asthma ED Visits", "O3-Attributable Asthma Hospitalizations "];
var filtered_data = {};
for (j = 0; j < variabelen.length; j++) {
var variable = variabelen[j]
var data = {};
for (var i = 0; i < airquality_data.length; i++) {
if (airquality_data[i].name == variabelen[j] && airquality_data[i].geo_type_name == "Borough" && airquality_data[i].year_description == "2005-2007") {
var key = airquality_data[i].geo_entity_name;
var value = airquality_data[i].data_valuemessage;
data[key] = value;
}
}
filtered_data[variable] = data;
var stack = d3.stack()
.keys("Bronx", "Brooklyn", "Staten Island", "Queens", "Manhattan")
.order(d3.stackOrderNone)
.offset(d3.stackOffsetNone);
var series = stack(filtered_data);
console.log(series);
});
答案 0 :(得分:0)
已找到解决方案,忘记在.keys()中添加括号,并且必须稍微更改filtered_data。