Hi, I seem to be stuck on this particular challenge with D3.
Everything I try doesn’t work. (d * 3) seems to put the bars in the right direction, but their heights are wrong.
Anyone can give me a hint? Your code so far
<body>
<script>
const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];
const w = 500;
const h = 100;
const svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
svg.selectAll("rect")
.data(dataset)
.enter()
.append("rect")
.attr("x", (d, i) => i * 30)
.attr("y", (d, i) => {
// Add your code below this line
return (d * 3)
// Add your code above this line
})
.attr("width", 25)
.attr("height", (d, i) => 3 * d);
</script>
</body>
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36.
try rereading the description, it explain how to account to the fact that the 0 point is at the top of the svg area
your code will work if the 0 point would be at the bottom of the svg area
I am understanding more, just have a little syntax question.
How do I change the y height in a return statement? It seems however I write it it throws an error.
I wish I could mark both of your answers as the solution because you both helped my efforts so much here.
Thank you both.
For future users who google this question