I am currently making two JSON requests in my code:
d3.json("path/to/file1.json", function(error, json) {
d3.json("path/to/file2.json", function(error, json2) {
});
});
The structure of json 2 looks like this:
[
{ "city" : "LA",
"locations" : [ { "country" : "USA", "x" : 0, "y" : 0 } ]
},
{ "city" : "London",
"locations" : [ { "country" : "UK", "x" : 0, "y" : 0 } ]
}
...
]
Currently, I'm trying to access the x & y values from json2. However, the issue I face is that I want to use both json and json2 in my variable:
var node = svg.selectAll("a.node")
.data(json.cars)
.enter().append("a")
.attr("class", "node")
;
Here, I need to fetch x & y positions ONLY from json2
node.attr("transform", function(d, i) {
return "translate(" + d.x + "," + d.y + ")";
});
node.append('path')
.attr("d", d3.svg.symbol().type(function(d) { return shape[d.name]; }).size(120))
.style("fill", function(d) { return colors[d.name]; } );
I have attempted the following:
node.attr("transform", function(d,i) {
return "translate(" + json2.locations[d].x + "," + json2.locations[d].y + ")";
});
But it didn't work. Any assistance would be appreciated - Thank you.