I would like to produce a scatter chart with their labels. The problem is that of course in some areas of chart, it gets dense and labels fall on each other. I was looking at D3 examples and the best thing among them was Force layout.
This is what I have done:
var force = d3.layout.force()
.linkDistance(20)
.size([availableWidth, availableHeight])
.nodes(labelsData)
.start();
force.on("tick", function() {
labelText.attr("x", function (d) {
return d.linkEndX;
})
.attr("y", function (d) {
return d.linkEndY;
})
.text(function(d) {return
d.name;});
});
The above code does not function, meaning that there is no animation and all that. The problem as I see it is that I have a constant linkDistance while in practice they get closer than that.
What can I really do about this. Is there something where I can tell D3 that the linkDistance is kind of an interval or something?
I just need two things: they almost have the x and y (since the data cannot be changed) but with a little change in x and y so that no labels collide.
Any help would be appreciated as always.
/Amir