Public
Edited
Apr 9
Insert cell
# Sparkline
Insert cell
<svg id="base" width="500" height="250">
<style>
.sparkline {fill:none; stroke: blue; stroke-width: 3; }
</style>
<g id="layer1" transform="translate(20 50)"></g>
<g id="layer2" transform="translate(20 150)"></g>
</svg>
Insert cell
import {world_gdp_growth_pivot} from "@emfielduva/dvlib_sampledata"
Insert cell
sortedData = world_gdp_growth_pivot.sort((a,b)=>d3.ascending(toNum(a["Year"]),toNum(b["Year"])));
Insert cell
scaleX = d3.scaleLinear().domain([1960,2012]).range([10,300])
Insert cell
scaleY = d3.scaleLinear().domain([-20,20]).range([50,0])
Insert cell
Insert cell
Insert cell
graph1Elem = d3.select(svgContainer).select("#layer1")
Insert cell
graph2Elem = d3.select(svgContainer).select("#layer2")
Insert cell
mySparkLine1 = dvSparkline(graph1Elem,sortedData,"Year","USA",scaleX,scaleY);
Insert cell
mySparkLine2 = dvSparkline(graph2Elem,sortedData,"Year","CHN",scaleX,scaleY);
Insert cell
Insert cell
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