Why do no numbers appear on my x-axis?

Hi all!

Why do no numbers appear on my x-axis?

Thanks for your time


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36

Challenge: Visualize Data with a Bar Chart

Link to the challenge:

Hi @jaimeggb ,

On your xScale, scaleLinear is being used and the domain passed is 0 to max of timeArray which is a string causing the conflict.

const xScale = d3.scaleLinear()
  .domain([0, d3.max(timeArray)])

You could use scaleTime and also convert the max and min of timeArray to a date for it to work.


it now works, thank you @manjupillai16 !

One other question regarding this matter: in line 36 of my code, why must I write ‘timeArray[i]’ for the code to work instead of just ‘d’? Aren’t ‘timeArray[i]’ and ‘d’ meant to be the same exact thing?

line 36: .attr("x", (d, i) => xScale(new Date(timeArray[i])))

For example, for the y axis I can use either ‘d’ or ‘gdpArray[i]’, they both work:

.attr("y", (d, i) => yScale(gdpArray[i]))    

.attr(“y”, (d, i) => yScale(d))
both work

That’s coz you’re passing the gdpArray as the dataset to the svg

    .data(gdpArray)   <--  change this to timeArray and the x co-ordinate will work with d
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.