[英]D3.js: Joining json and csv not working
I want to create a map with the static map in a json file and the dynamic data in a csv file. 我想用json文件中的静态地图和csv文件中的动态数据创建地图。 The map displays but the dynamic data from the cvs file is not working.
显示地图,但cvs文件中的动态数据不起作用。 I've attempted to follow mbostock's explanations but so far I can't get the join to work.
我试图按照mbostock的说明进行操作,但到目前为止,我还没有加入工作。 Here is the code:
这是代码:
d3.json("/sites/default/d3_files/json/toronto-wards.json", function(error,wards) {
var csvData;
d3.csv("/csv-pledges", function(error, csv)
{
csvData = csv;
alert ("Hello" +csvData); // this displays
joinJsonCsv(csvData);
alert ("Bye"); // doesn't display
}); // end d3.csv
function joinJsonCsv(csv) {
// do something with rows
alert ("joinJsonCsv" +csv); // this displays
csv.forEach(function(d, i) {
alert("the value of e.SCODE_NAME is: "+e.SCODE_NAME); // doesn't display
world.forEach(function(e, j) {
if (d.ward_no === e.SCODE_NAME)
{
e.NAME = d.ward_no
} // end ward test
}) // end world loop loop
})// end of csv loop
alert ("exit joinJsonCsv"); // this doesn't display
} // end joinJsonCsv
What am I missing? 我想念什么?
You were referencing the e
object outside of its scope so the function was crashing. 您在
e
对象的范围之外引用了e
对象,因此该函数崩溃了。 I moved the alert so that e
is defined, it should work now. 我移动了警报,以便定义
e
,它现在应该可以工作。 d3.json("/sites/default/d3_files/json/toronto-wards.json", function(error,wards) { var csvData; d3.csv("/csv-pledges", function(error, csv) { csvData = csv; d3.json(“ / sites / default / d3_files / json / toronto-wards.json”,function(error,wards){var csvData; d3.csv(“ / csv-pledges”,function(error,csv){csvData = csv;
alert ("Hello" +csvData); // this displays
joinJsonCsv(csvData);
alert ("Bye"); // doesn't display
}); // end d3.csv
function joinJsonCsv(csv) {
// do something with rows
alert ("joinJsonCsv" +csv); // this displays
csv.forEach(function(d, i) {
world.forEach(function(e, j) {
alert("the value of e.SCODE_NAME is: "+e.SCODE_NAME); // try this maybe
if (d.ward_no === e.SCODE_NAME)
{
e.NAME = d.ward_no
} // end ward test
}) // end world loop loop
})// end of csv loop
alert ("exit joinJsonCsv"); // this doesn't display
} // end joinJsonCsv
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.