Public
Edited
Dec 13, 2023
1 star
Insert cell
Insert cell
lineChart(data, "Alternative data", 10, "Google searches for\n\"alternative data\"")
Insert cell
Insert cell
cell_width = 280
Insert cell
cell_height = 130
Insert cell
function lineChart(data, variable, years, title) {
return Plot.plot({
marks: [
Plot.text([title], { x: d3.utcYear.offset(new Date(), -(years - 1)), y: d3.max(data.filter(d => d.variable === variable), v => v.value) - d3.max(data.filter(d => d.variable === variable), v => v.value) / 20, textAnchor: "start" }),
Plot.lineY(
data.filter(d =>
d.variable === variable &&
d.date >= d3.utcYear.offset(new Date(), -years)
),
{ x: "date", y: "value", curve: "catmull-rom" }
),
],
y: {
label: null,
tickFormat: d3.format(",.2s"),
domain: [
d3.min(data.filter(d => d.variable === variable), v => v.value),
d3.max(data.filter(d => d.variable === variable), v => v.value) +
d3.max(data.filter(d => d.variable === variable), v => v.value) * .2
]
},
width: cell_width,
height: cell_height,
marginTop: -10
})
}
Insert cell
data1 = FileAttachment("data@1.csv").csv()
Insert cell
function bigNumber(data, variable, title) {
return Plot.plot({
marks: [
Plot.text([title], {
frameAnchor: "top",
lineHeight: 1.5
}),
Plot.text([Math.round(data.find(d => d.variable === variable).value)], {
frameAnchor: "middle",
fontSize: 80
})
],
width: cell_width,
height: cell_height,
style: {
background: "black",
color: "white"
}
})
}
Insert cell
data = FileAttachment("data@2.csv").csv({ typed: true }).then(d => d.map(e => ({ ...e, variable: "Alternative data" })))
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