Learn Observablehq - 10 Code Examples & CST Typing Practice Test
ObservableHQ is a web-based platform for reactive JavaScript notebooks, primarily used for data visualization, analysis, and interactive computational documents. It allows users to create dynamic, shareable notebooks that update automatically as underlying data changes.
Learn OBSERVABLEHQ with Real Code Examples
Updated Nov 26, 2025
Code Sample Descriptions
Hello World in ObservableHQ
md`Hello World`
A simple Observable cell displaying 'Hello World'.
Simple Bar Chart (D3.js)
import {scaleBand, scaleLinear, max} from "d3"
const data = [4, 8, 15, 16, 23, 42]
const x = scaleBand()
.domain(d3.range(data.length))
.range([0, 420])
.padding(0.1)
const y = scaleLinear()
.domain([0, max(data)])
.range([0, 120])
svg`<svg width=420 height=120>
${data.map((d, i) => `<rect x="${x(i)}" y="${120 - y(d)}" width="${x.bandwidth()}" height="${y(d)}"></rect>`).join("")}
</svg>`
A basic D3.js bar chart defined in an Observable cell.
Reactive Slider Example
viewof n = Inputs.range({min: 1, max: 100, step: 1, value: 50})
md`Value: **${n}**`
A slider input that updates the displayed value reactively.
Live Time Display
import {now} from "@observablehq/stdlib"
md`${now}`
A cell that automatically updates to show the current time.
Simple Line Plot (Plot.js)
import * as Plot from "@observablehq/plot"
Plot.plot({
marks: [
Plot.lineY([1, 4, 2, 8, 3])
]
})
A basic line chart using Observable Plot.
Fetch Remote JSON
data = fetch("https://jsonplaceholder.typicode.com/todos/1").then(r => r.json())
Loads JSON data from a URL inside an Observable cell.
HTML Template Cell
html`<div style="padding:20px; background:#eee;">Hello from HTML!</div>`
Renders custom HTML inside a notebook cell.
Mutable State Example
mutable counter = 0
button = html`<button>Increment</button>`
button.onclick = () => mutable counter++
md`Counter: **${counter}**`
Uses mutable state to update a counter.
Random Number Stream
import {Generators} from "@observablehq/stdlib"
Generators.observe(notify => {
setInterval(() => notify(Math.random()), 1000)
})
Generates a new random number every second using Generators.
D3 Scatter Plot
import * as d3 from "d3"
const data = Array.from({length: 20}, () => ({x: Math.random()*100, y: Math.random()*100}))
svg`<svg width=300 height=300>
${data.map(d => `<circle cx="${d.x}" cy="${d.y}" r="4" fill="steelblue"></circle>`).join("")}
</svg>`
A simple scatter plot made with D3.js.
Frequently Asked Questions about Observablehq
What is Observablehq?
ObservableHQ is a web-based platform for reactive JavaScript notebooks, primarily used for data visualization, analysis, and interactive computational documents. It allows users to create dynamic, shareable notebooks that update automatically as underlying data changes.
What are the primary use cases for Observablehq?
Creating interactive data visualizations. Exploring datasets with live code experiments. Prototyping reactive visual analytics. Teaching and demonstrating JavaScript and D3 concepts. Collaborative analysis and storytelling with data
What are the strengths of Observablehq?
Highly interactive and reactive environment. Excellent for data visualization and exploratory analysis. Easy collaboration and sharing of notebooks. Supports rich visual storytelling with data. Immediate feedback for code changes
What are the limitations of Observablehq?
Focused mainly on front-end JavaScript and visualization. Not a general-purpose IDE for backend development. Performance may lag with extremely large datasets. Limited offline functionality. Requires browser and modern JavaScript knowledge
How can I practice Observablehq typing speed?
CodeSpeedTest offers 10+ real Observablehq code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.