I think I have a question that's pretty simple but I can't figure it out. My array is as follows:
var wordcount = [1, 2, 3, [{name: 'A', values: [0,1,3,9, 8, 7]},
{name: 'B', values: [0, 10, 7, 1, 1, 11]},
{name: 'C', values: [3, 1, 4, 4, 4, 17]},
{name: 'D', values: [4, 77, 2, 13, 11, 13]}
]]]
and I'm using the following code to get A, B, C, and D
d3.select("#tooltippos")
.data(d[3])
.enter()
.append("div")
.text(function(d) { return d.name; });
but I keep missing the first letter. Only B, C, and D show up in the divs.
You need to select the non-existent elements as well for the selections to work properly. That is, your code should be
d3.select("#tooltippos").selectAll("div")
.data(d[3])
.enter()
.append("div")
.text(function(d) { return d.name; });
At the moment, the selection you're matching data against contains only the one element ("#tooltippos"), which is matched with the first element of the data. Hence, this is not in the enter selection and not drawn.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With