Sparkline

1 - Example

function sparkline(values, width = 64, height = 17) {
  const x = d3.scaleLinear().domain([0, values.length - 1]).range([0.5, width - 0.5]);
  const y = d3.scaleLinear().domain(d3.extent(values)).range([height - 0.5, 0.5]);
  canvas = document.getElementById("graph");
  context = canvas.getContext("2d");
  const line = d3.line().x((d, i) => x(i)).y(y).context(context);
  context.beginPath(), line(values), context.stroke();
}
 
sparkline([0, 8, 3, 2, 6, 5, 1]);
<canvas id="graph" width="64" height="17"></canvas>

data/viz/sparkline.txt ยท Last modified: 2018/03/28 23:02 by gerardnico