I'm trying to append image urls to an SVG element using D3. I've tried various codes including this one.
svg.append('g')
.selectAll('image')
.data(data)
.enter()
.append('image')
.attr('class', 'countryflag')
.attr('href', `https://www.musiktrends.com/images/countryflags/`
+
data.map(yValues)
+
`.png`)
.attr('width', 50)
.attr('height', barHeight)
.attr('x', 0)
.attr('y', yPos)
.attr(`transform', `translate(5,`+0+`)`)
;
The problem with this code is that I get all countries in the url. I only want the country that corresponds to each value in the json array.
Here's the data array:
data = d3.json('data.json')
.then(data => {data
.forEach(d => {
d.country = d.country;
d.population = +d.population * 1000;
});
render(data);
});
I've tried writing a function as well but because I'm fairly new at this I couldn't figure it out. Thank you all in advance.