Published
Edited
Dec 19, 2020
Importers
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
height = 400
Insert cell
margin = 50
Insert cell
colors = d3.schemeCategory10
Insert cell
x = d3.scaleLinear()
.domain([0, numberOfDataPoints])
.range([0, chartWidth])
Insert cell
y = d3.scaleLinear()
.domain([0, maxY])
.range([chartHeight, 0])
Insert cell
chartWidth = width - 2 * margin
Insert cell
chartHeight = height - 2 * margin
Insert cell
dotRadius = 2
Insert cell
curves = ({
"Basis": d3.curveBasis,
"Linear": d3.curveLinear,
"Natural": d3.curveNatural,
"Step": d3.curveStep
})
Insert cell
curve = curves[curveName]
Insert cell
function renderAxes(svg) {
svg.append("g")
.attr("transform", `translate(${margin},${height - margin})`)
.call(d3.axisBottom(x.domain([0, numberOfDataPoints - 1])));

svg.append("g")
.attr("transform", `translate(${margin},${margin})`)
.call(d3.axisLeft(y).ticks(5));
}
Insert cell
lineChart.render(generateData)
Insert cell
Insert cell
numberOfSeries = 3
Insert cell
numberOfDataPoints = 10
Insert cell
maxY = 50
Insert cell
randomY = d3.randomUniform(0, maxY)
Insert cell
function data() {
return d3.range(numberOfSeries).map(() => {
return d3.range(numberOfDataPoints).map((_, i) => ({ x: i, y: randomY() }))
})
}
Insert cell
generateData = {
while (true) {
yield await Promises.tick(1000, data())
}
}
Insert cell
Insert cell
d3 = require("d3@6")
Insert cell
import {select} from "@jashkenas/inputs"
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