Published unlisted
Edited
Jul 13, 2021
Insert cell
md`# Testing Plot with SP500`

Insert cell
sp500 = FileAttachment("sp500.csv").csv({typed: true})
Insert cell
data = sp500.map(d => {
return {
...d,
date: parser(d.date)
}
})
Insert cell
md`### Format date accordingly, MMM day YYYY`
Insert cell
parser = d3.timeParse("%b %d %Y")

Insert cell
md`### Get first and last array for date`
Insert cell
startDate = parser(sp500[0].date)
Insert cell
endDate = parser(sp500[122].date)
Insert cell
md`### Format X axis labels`
Insert cell
Plot.plot( {x: {type: "time", domain: [startDate, endDate]}, grid: true})
Insert cell
md` ## x-axis dates too close to each other`
Insert cell
Plot.dot(data, { x: "date", y: "price", stroke:"price" }).plot({
width:1200,
height: 600,
grid: true,
inset: 10,
y: {
label: "Price",
padding: 0.1
},
x: {
label: "Month",
padding: 0.1,
},
})
Insert cell
md` ### How to format date in month?`
Insert cell
Plot.plot({
grid: true,
width:1200,
height: 600,
marks: [
Plot.ruleY([0]),
Plot.dot(sp500, {x: {type: "time", domain: [startDate, endDate]}, y: "price", stroke: "price"})
]
})
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