Public
Edited
Apr 19, 2024
Insert cell
Insert cell
data = [
{year: 2000, aapl: 1, msft: 49.38, ibm: 115.81},
{year: 2010, aapl: 6.86, msft: 28.96, ibm: 116.90},
{year: 2020, aapl: 77.57, msft: 167.10, ibm: 130.56}
]
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.lineY(data, {x: "year", y: "aapl", stroke: "red"}),
Plot.lineY(data, {x: "year", y: "msft", stroke: "green"}),
Plot.lineY(data, {x: "year", y: "ibm", stroke: "blue"}),
]
})
Insert cell
Insert cell
Plot.legend({color: {domain: ["aapl", "msft", "ibm"], range: ["red", "green", "blue"]}})
Insert cell
Insert cell
tidy = data.flatMap(({year, ...stocks}) => Object.entries(stocks).map(([stock, value]) => ({year, stock, value})))
Insert cell
Insert cell
Plot.plot({
color: {legend: true},
marks: [
Plot.lineY(tidy, {x: "year", y: "value", stroke: "stock"})
]
})
Insert cell
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