Published
Edited
May 16, 2022
Insert cell
Insert cell
activity = [
{"Activity": "Sleeping", "Time": 8},
{"Activity": "Eating", "Time": 2},
{"Activity": "TV", "Time": 4},
{"Activity": "Work", "Time": 8},
{"Activity": "Exercise", "Time": 2}
]
Insert cell
Insert cell
vl.markBar()
.data(activity )
.encode(
vl.x().fieldN('Activity'), // x-axis is countries
vl.y().fieldQ('Time'),
).render();
Insert cell
Insert cell
vl.markBar()
.data(activity )
.transform(
vl.joinaggregate({"op": "sum", "field": "Time", "as": "TotalTime"}),
vl.calculate("datum.Time/datum.TotalTime * 100").as("PercentOfTotal")
).encode(
vl.x().fieldN('Activity'), // x-axis is countries
vl.y().fieldQ('PercentOfTotal').title("Percent of Total"),
).render();
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