Public
Edited
Oct 31, 2023
Insert cell
Insert cell
Plot.plot({
height: 15,
x: { domain: [0, 100], label: "", axis: null },
marks: [Plot.tickX(data, { x: "index", stroke: "color", strokeWidth: 4 })]
})
Insert cell
function generateObjectsWithColor(share) {
if (share < 1 || share > 100) {
throw new Error("Share parameter must be between 1 and 100");
}

const result = [];

for (let index = 1; index <= 100; index++) {
const color = index <= share;
result.push({ index, color });
}

return result;
}
Insert cell
data = generateObjectsWithColor(80)
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