Basiclly I have an Array of some Strings and I want to bind each of this strings to an circle. Then when I hover over the Circle I want to display these strings in a tooltip.
So this is my Array:
var node = [
"Hallo Hallo Hallo Hallo Hallo Hallo Hallo",
"foobarbaz",
"This is a short text",
"Changed some things on the folder structure and added some functions to the convert.c file",
];
Then there is my Tooltip which displays a html text...
var tooltip = svg.append('foreignObject')
.attr('x', 50)
.attr('y', 50)
.attr('width', 200)
.attr('height', 300)
.style("visibility", "hidden")
.append("xhtml:body")
.html('<div style="width: 150px;">Example</div>');
And now I want to create my circles over a for loop, append the data to them and let the tooltip display the right data on a mouseover:
for (var i = 0; i < 4; i++) {
svg.append("circle")
.data(node[i])
.attr("cx", 100*i+250)
.attr("cy", 100)
.attr("r", 10)
.attr("fill", "steelblue" )
.on("mouseover", function(d){
return tooltip.style("visibility","visible")
.html('<div style="width: 150px;">'+d+'</div>');
}).on("mouseout", function(){
return tooltip.style("visibility", "hidden");
});
}
But for some reason the result is not the whole string when I hover over the points it is just the fist character of the string. I am obviously missing something here...
.datum()instead of.data(). You really shouldn't be using a loop here though but D3's selections and data matching.