Published unlisted
Edited
Oct 18, 2021
Insert cell
Insert cell
Insert cell
// text = d3.text(url) // this returns a string
Insert cell
Insert cell
d3.csv(url) // No auto typing -- notice that the CSV is parsed and values are strings (double quotes).
Insert cell
Insert cell
data = d3.csv(url, d3.autoType) // With d3.autoType -- types seem to have been guessed correctly
Insert cell
Insert cell
Insert cell
dataParsed = d3.csv(url, d3.autoType)
Insert cell
Insert cell
typeof data[0].date
Insert cell
data2 = {
const text = await d3.text(url);
const parseDate = d3.utcParse("%Y-%m-%d");
const data = d3.csvParse(text, ({Date, Open}) => ({
date: parseDate(Date), // This uses d3.
open: +Open // The leading "+" coerces the string to a number
})); // You could remove .columns by with .splice()
delete data.columns; // remove .columns created by d3-csv, it has original keys and confuses Inputs.table()
return data;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
marginLeft: 70,
y: {
grid: true,
label: "Yearly average"
},
marks: [
Plot.line(data, Plot.windowY({x: "Date",
y: d => (d.Close - d.Open) / d.Open,
k: 252})),
]
})
Insert cell
Insert cell
Insert cell
Plot.plot({
y: {
grid: true,
},
marks: [
Plot.line(data, Plot.windowY({x: "Date",
y: d => d.Close,
k: 252,
reduce: "mean"})),
]
})
Insert cell
Plot.plot({
y: {
grid: true,
},
marks: [
Plot.line(data, {x: "Date", y: "Close"}),
]
})
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more