I'm a pretty new to D3 and after two days I am still stuck with an issue I can't solve.
I have a this JSON structure:
var countries = [
{
name: "Germany",
total:1000,
bars:[
{
color: '#123456',
values: [100,200]
},
{
color: '#123456',
values: [100,200]
}
]
},
{
name: "Sweden",
total:800,
bars:[
{
color: '#cccccc',
values: [100, 300]
}
]
},
{
"name":"Netherlands",
total:200,
bars:[
{
color: '#123456',
values: [100,200]
}
]
}
];
What I am trying to achieve is to build an html structure of this type:
<ul class="ranking">
<!--one li element per object inside countries JSON structure -->
<li>
<ul class="bar">
<!--one li element per bar object inside each country -->
</ul>
</li>
</ul>
I can easily build the first unordered list in this way:
var rankingUL = svg.append("ul").attr ("class", "ranking")
var rankingLI = rankingUL.selectAll("li")
.data(countries)
.enter()
.append("li")
var rankingULBars = rankingLI.append("ul").attr("class", "bar");
but then I have some big issue to understand how to create the second nested list. What I am basically missing is to understand how to recursively create another list inside each list item, containing a list item per each bar. Any help or explanation is really appreciated