Two that are failing:
- Each bar element’s height should accurately represent the data’s corresponding GDP
and
- The data-date attribute and its corresponding bar element should align with the corresponding value on the x-axis.
This other fCC forum post recommends using d3.scaleTime() instead of d3.scaleLinear() but that didn’t fix my issue. Also, I wrote a convertDate() helper which takes in a string and returns a Date() object already so that the xScale works properly.
I get the data-date issue when I pass in d[0] and convertDate(d[0]) so not sure what the issue is there.
For #9, here is how I set the height of the bars:
const yScale = d3.scaleLinear()
.domain([0
d3.max(gdp, (d) => d[1])])
.range([h-padding, padding])
Perhaps 0 should be d3.min(gdp, (d) => d[1])
instead? This forum post recommended scaling from minimum to maximum. That also didn’t fix it. Specifically in the code I set my bar height like this:
.attr("y", (d,i) => (yScale(d[1])) + "px")
.attr("height", (d, i) => {
return h-padding + "px";
})
Here’s my Codepen—thanks in advance!
PS—if anyone on fCC staff is reading this, the way tooltips are taught in the curriculum does not pass the tests. This post has a code snippet I (properly attributed and) used for how it actually works, but without prior knowledge of D3/looking on the forum I wouldn’t have been able to solve it.