I can't figure out how to set the size of my d3 symbols in this:
legendRectE
.append('path')
.attr("d", d3.svg.symbol().type((d) => { return d[2] }))
.style("fill", function (d) {
return d[1];
})
.attr('stroke', 'black');
I tried to use .size()
like this, but it didn't work:
legendRectE
.append('path')
.attr("d", d3.svg.symbol().type((d) => { return d[2] }))
.style("fill", function (d) {
return d[1];
})
.attr('stroke', 'black')
.size(20*20);
When I try using .size()
like that, I get an error: [ts] Supplied parameters do not match any signature of call target.
So how can I set the size of my symbols in this case?
D3 uses SVG to create and modify the graphical elements of the visualization. Because SVG has a structured form, D3 can make stylistic and attribute changes to the shapes being drawn.
var circle = d3. selectAll("circle"); With a selection, we can make various changes to selected elements.
Built-in Symbols To use them, assign them in the . type(symbol) method on the symbol generator: var square = d3. symbol().
I have the following code that draws a triangle in d3: var trianglePoints = xScale(3) + ' ' + yScale(18) + ', ' + xScale(1) + ' ' + yScale(0) + ', ' + xScale(12) + ' ' + yScale(3) + ' ' + xScale(12) + ', ' + yScale(3) + ' ' + xScale(3) + ' ' + yScale(18); console. log(trianglePoints); svg. append('polyline') .
You have to define the size
in the symbol generator (the d3.svg.symbol
function):
d3.svg.symbol().size(size).type(foo);
//size here-----------^
Here is a demo:
var svg = d3.select("svg");
var sizes = ["10", "50", "100", "200", "500", "1000", "2000"];
sizes.forEach((d, i) => {
svg.append('path')
.attr("transform", "translate(" + (10 + (i+1) * (i+1) * 5) + ",100)")
.attr("d", d3.svg.symbol().size(d).type("diamond"))
.style("fill", "gold")
.attr('stroke', 'black');
});
<script src="https://d3js.org/d3.v3.js"></script>
<svg></svg>
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