Public
Edited
May 5, 2023
Insert cell
Insert cell
Insert cell
myDate = new Date("2022-01-01") // a date value. change it and see what happens.
Insert cell
scaleDate(myDate) // returns a value between 20 and 800, proportional to date within minDate to maxDate
Insert cell
scaleDate = d3.scaleTime().domain([minDate,maxDate]).range([20,800]) // fits date range to the line x range (x=20 to 800)
Insert cell
minDate = new Date("2020-01-01")
Insert cell
maxDate = new Date("2023-05-09")
Insert cell
d3.select(mySVG).selectAll("circle").data([myDate]).join("circle").attr("cx",d=>scaleDate(d)).attr("cy",100).attr("r",5)
// just drawing the dot
Insert cell
Insert cell
Insert cell
Insert cell
viewof slider = Inputs.range([0, countOfDays], {label: "Date", step: 1, width: 500})
Insert cell
sliderDate = d3.timeDay.offset(minDate,slider) // return date that is slider days from minDate
Insert cell
countOfDays = d3.timeDay.count(minDate,maxDate) // number of days
Insert cell
d3.select(mySVG2).selectAll("circle").data([sliderDate]).join("circle").attr("cx",d=>scaleDate(d)).attr("cy",100).attr("r",5)
// just drawing the dot
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more