2017-01-22 1 views
1

上の座標と地図上のプロット空港のマップ点をd3.js LAXまたはJFKとして。 座標は別のjsonファイルにあります。 私は関数plot_airportsを使用しています。私の問題は、座標を持つ空港コードをデータ変数に結合する方法です。空港コードを読み込むためのは私がd3.js</p>ソースファイルが唯一の空港コードを持っているCSV一つです <p>、などで地図上の米国の空港をプロットしたい別のファイル

function plot_airports(data) { 
     svg.append('g') 
      .attr("class", "airports") 
      .selectAll("circle") 
      .data(data) 
      .enter() 
      .append("circle") 
      .attr('cx', function(d) {return projection([d.lon,d.lat])[0]; }) 
      .attr('cy', function(d) {return projection([d.lon,d.lat])[1]; }) 
      .attr('r', 5) 

機能は以下の通りです:

d3.csv("sample.csv",function(d) { 
    return d["airport"]; 
    }); 

と空港との1:

d3.json("airports.json"); 

私は、変数に各関数の結果を保存しようとしました空港コードをキーとして参加させたが、その結果の変数は空だった。

ありがとうございました!

答えて

0

d3.csv関数は、変数に割り当てることができる使用可能な値を返しません。つまり、あなたはできません:

var foo = d3.csv("sample.csv",function(d) { 
    return d["airport"]; 
}); 

これは単に動作しません。

d3.json("airports.json", function(dataCoordinates) { 

    //get the airports coordinates in an array named 'dataCoordinates' 

    d3.csv("sample.csv", function(dataCodes) { 

     //get the airports codes in an array named 'dataCodes'; 
     //create your circles accessing both arrays, or join the arrays 
     //using the airport code as key. 

    }); 

}); 

溶液を入れ子 2つの非同期関数であります