Public
Edited
Oct 19, 2022
Insert cell
Insert cell
Insert cell
import { SummaryTable } from "@observablehq/summary-table"
Insert cell
SummaryTable(data)

Insert cell
filter = d3.timeParse("%Y-%m-%dT%H:%M:%S.%LZ")("2022-10-16T13:03:14.604Z")
Insert cell
data_filtered = data.filter((d) => d.date < filter)
Insert cell
SummaryTable(data_filtered)
Insert cell
viewof movingavgWindow = Inputs.range([1, 200], {
step: 1,
label: "Window size"
})
Insert cell
Insert cell
Plot.dot(data_filtered, {
x: "date",
y: "state",
title: "title",
fill: (d, i) => (d.state > movingAvg[i] + 5 ? 1 : 0) // adding 5 since we want to highlight points that are a least a bit *above* the moving average
}).plot({
y: { grid: false },
marks: [
Plot.ruleX(data_filtered, {
x: "data",
y: "state",
stroke: "#eee",
strokeWidth: 2
}),
Plot.line(
data_filtered,
Plot.windowY({
x: "date",
y: (d) => d.state + 5,
k: movingavgWindow,
stroke: "rebeccapurple",
shift: "trailing"
})
),
Plot.ruleY([0])
],
marginLeft: 30,
marginBottom: 100,
marginRight: 50,
width: width,
color: {
range: ["steelblue", "orange"]
}
})
Insert cell
Plot.plot({
y: {
grid: true,
type: "log"
},
marks: [Plot.line(data_filtered, { x: "date", y: "state" })]
})
Insert cell
viewof bins = Inputs.range([3, 20], {step: 1, label: "Bins"})
Insert cell
Plot.plot({
marks: [
Plot.ruleY([0]),
Plot.rectY(data, Plot.binX({ y: "sum" }, { x: "state", thresholds: bins }))
]
})
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