Public
Edited
Dec 16, 2022
Fork of SQL + Chart
Insert cell
Insert cell
viewof file = Inputs.file()
Insert cell
csv = {
const txt = await file.text();
return d3
.csvParse(txt.split("\n").slice(2).join("\n"), d3.autoType)
.map((row) => {
return {
...row,
date: new Date(row["Acquired date"])
};
});
}
Insert cell
database = DuckDBClient.of({
costbasis: csv
})
Insert cell
database
SELECT * from costbasis where "Symbol/CUSIP" = 'VTI';
Insert cell
query = database.query(
`SELECT * from costbasis where "Symbol/CUSIP" = '${ticker}'`
)
Insert cell
database
SELECT DISTINCT("Symbol/CUSIP") as ticker from costbasis;
Insert cell
viewof ticker = Inputs.select(tickers.map((t) => t.ticker))
Insert cell
Plot.plot({
caption: "Cost per share",
width,
x: {
label: "Date"
},
marks: [
Plot.ruleY([0]),
Plot.dot(query, { y: "Cost per share", x: "date", r: "Total cost" })
]
})
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