I’m losing my mind over finishing my first D3 project to visualize the US GDP bar chart (https://codepen.io/spreeni/pen/bQwoGN). I can’t get my x-axis to display just ticks for every 5 years or so. Right now it just takes the automatically chosen ticks and they’re not very pretty. Two of the test cases also keep failing, apparently
The bar elements’ “data-date” properties don’t match the order of the provided data
The data-date attribute and its corresponding bar element don’t align with the corresponding value on the x-axis.
Which implies that my scaling for my xAxis is off I guess, but I can’t find a mistake.
And for the tick problem, I have tried multiple things to costumize the ticks, including
xAxis.ticks(d3.timeYear,5)
xAxis.ticks(d3.timeYear.every(5))
xAxis.ticks(d3.timeYear.every(5).range(new Date(1950, 0, 1), new Date(2015, 0, 1)))
Thanks for the answer, but I tried that before already. It just automatically sequences again and doesn’t let me customize it. I found solutions online, but for some reason they don’t work for my chart. All my x-values are Date types, so it should work with these functions. Down below I listed some sources I’ve checked out already, maybe someone can see sth I don’t.
Thank you!! It was right in front of my eyes I guess. Now a last test doesn’t compute, it still doesn’t pass the test for
The bar elements’ “data-date” properties should match the order of the provided data
Any ideas? Because I can’t really find a way how that wouldn’t be the case. And I did it analog to the data-gdp value, which passes the test. Here is my code for the bars: