<script type="text/javascript">
var divElem = d3.select("#svgpathSVGdata");
data for squares
var jsonsquare = [{
x: 40,
y: 170,
width: 120,
height: 120,
label: "technology"
},
];
setting the canvas with of course width & height declared already
var svgcanvas = divElem.append("svg:svg")
.attr("width", w).attr("height", h);
This is the relevant coding… for some reason it doesn’t generate a square
var square = svgcanvas.selectAll("rect").data(jsonsquare);
circle.enter().append('svg:rect').append("svg:g")
.attr('opacity', 0)
.attr("cursor", "pointer");
}).attr("x", function(d) {
return d.x;
}).attr("y", function(d) {
return d.y;
}).attr("width", function(d) {
return d.width;
}).attr("height", function(d) {
return d.height;
});
linking label to the squares
svgcanvas.selectAll("text").data(jsonsquare).enter().append("svg:text").text(function(d) {
return d.label;
}).attr("x", function(d) {
return d.x + 10;
}).attr("y", function(d) {
return d.y + 10;
});
</script>
You’re assigning the rectangle’s attributes to the group (i.e,
svg:g) beneath it. In the line below, remove the.append("svg:g")and it should work.Also, you’re setting opacity to zero:
This makes your rectangle invisible. Set it to 1 instead for full visibility, or some number in between for a translucent fill effect.