I am using D3, Javascript, HTML and the function d3.scaleTime()
What is wrong with the way I input Dates with the scaleTime() function in d3?
I am currently trying to make an x-axis with d3, based on time using d3.scaleTime().
However whenever i input the timeData to scaleTime.domain() no data shows on my axis.
I get a blank axis.
The section of code I think my bug is coming from is here:
JavaScript
x
6
1
let timeData = ["2020-10-05", "2000-10-04"]
2
3
d3.scaleTime()
4
.domain( [timeData[0], timeData[1] )
5
.range( [0,400] )
6
I have tried changing timeData to [2020-10-05, 2000-10-04]
However I then get decimal points on my axis.
any help is appreciated
Advertisement
Answer
you need to pass min and max values as Date Formats on scaleTime.
JavaScript
1
4
1
d3.scaleTime()
2
.domain( new Date(timeData[0]), new Date(timeData[1]) )
3
.range( [0,400] )
4
Also note that min value is lesser than max value.
Reason its not working is that it is considering them as String values.