简体   繁体   English

D3 / Javascript代码难题?

[英]D3/Javascript code conundrum?

I have the following code: 我有以下代码:

d3.csv("flights-airport_3.csv", function(flights) {

var linksByOrigin = {},
  countByAirport = {},
  cancelledByAirport = {},
  locationByAirport = {},
  positions = [];

var arc = d3.geo.greatArc()
  .source(function(d) { return locationByAirport[d.source]; })
  .target(function(d) { return locationByAirport[d.target]; });

flights.forEach(function(flight) {
var origin = flight.origin,
    destination = flight.destination,
    count_airport = flight.count,
    cancelledByAirport = flight.count_cancelled,
    links = linksByOrigin[origin] || (linksByOrigin[origin] = []);
links.push({source: origin, target: destination});

My flights data array looks like this: 我的航班数据数组如下所示:

0: Object "": "" count: "9" count_cancelled: "0" destination: "IAD" origin: "ALB" 0:对象“”:“”计数:“ 9” count_cancelled:“ 0”目的地:“ IAD”来源:“ ALB”

For some reason my cancelledByAirport is empty? 由于某些原因,我的cancelledByAirport为空? I am not sure why since I am treating it exactly the same as my countByAirport variable. 我不确定为什么,因为我将其与我的countByAirport变量完全一样。 Can anyone help? 有人可以帮忙吗?

I think your problem is that you have two variables called "cancelledByAirport". 我认为您的问题是您有两个名为“ cancelledByAirport”的变量。 One is declared just below d3.csv(...), another within foreach(). 在d3.csv(...)下面声明一个,在foreach()中声明另一个。

The solution would be giving different names to those variables, or perhaps getting rid of one of them. 解决方案是为这些变量使用不同的名称,或者摆脱其中之一。

Please review your code with respect to those two variables, and tell us what you find. 请查看关于这两个变量的代码,并告诉我们您的发现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM