I have two separate CSV files, sharing an attribute:
File 1
name,total
Frank,13
Mary,24
Jim,46
File 2
name,desc
Frank,yellow
Mary,blue
Jim,green
How can I map the attribute desc
to the File 1 so, let's say, when I hover on Frank, I will see "13" and "yellow"?
Currently, my code is looking like this:
d3.csv("data/csv/bilancio-missioni-desc.csv", function(descrizione) {
data = descrizione.map(function(data){
div.html("<h3>" + d.name + "</h3>" + "<p>" + data.desc + "</p>")
})
The problem is that d.name
and data.desc
(from File 1 and File 2) don't match — I can understand it's because I didn't combine them so they can share the common attribute name
, but I don't know how to write the right piece of code.
UPDATE My code so far:
d3.csv("data/csv/bilancio-tipologiedispesa-nest.csv", function(data1) {
d3.csv("data/csv/bilancio-missioni-desc.csv", function(data2) {
//code that depends on both data1 and data2
data1.forEach(d => {
data2.forEach(e => {
if (d.name === e.name) {
d.desc = e.desc;
}
});
});
// Fade all the segments.
d3.selectAll("path")
.style("opacity", .3);
vis.selectAll("path")
.filter(function(node) {
return (sequenceArray.indexOf(node) >= 0);
})
.style("opacity", 1);
div.transition()
.duration(200)
.style("opacity", .9);
div.html("<h3>" + d.name + "</h3>" + "<p>" + d.desc + "</p>");
});
});
}
If I console.log(data1), "desc" (from data2) is appended to data1 (yay!). But "d.desc" is returning "unidefined" in the HTML.