Published
Edited
Oct 27, 2020
5 stars
Insert cell
Insert cell
Insert cell
// make a "chart"
chart = {
// Create your svg
const svg = d3.create("svg")
// Store a legend in a variable
const color_legend = legend({
color: d3.scaleSequential([0, 100], d3.interpolateViridis),
title: "Temperature (°F)"
})
// Append your legend, which requires using a *function*
svg.append("g")
.attr("transform", "translate(10, 0)") // appending a G so you can easily position it
.append(() => color_legend)
// {make the rest of your chart here..... axes, marks, etc.}
// Return the chart
return svg.node()
}
Insert cell
md`## Appendix`
Insert cell
d3 = require("d3")
Insert cell
import {legend} from "@d3/color-legend"

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