Published
Edited
Nov 7, 2021
Fork of Bar Chart
Insert cell
# Line Chart
Insert cell
renderLineChart(data)

Insert cell
data = [{month: 12, sessions: 142},
{month: 11, sessions: 100},
{month: 10, sessions: 98},
{month: 9, sessions: 112},
{month: 8, sessions: 98},
{month: 7, sessions: 112}]
Insert cell
renderLineChart = function renderLineChart(data,property) {
let domain = "";
let range = "";
if(!property){
let keys = Object.keys(data[0]);
for (let index = 0; index < keys.length; ++index) {
if (typeof data[0][keys[index]] === "number") {
domain = keys[index];
break;
}
}
for (let index = 0; index < keys.length; ++index) {
if (typeof data[0][keys[index]] === "number" && keys[index] !== domain) {
range = keys[index];
break;
}
}
}else{
domain = property.domain;
range = property.range;
}

return Plot.plot({
marks: [
Plot.line(data, {x: domain, y: range})
]
})
}
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