All examples By author By category About

ColinEberhardt

d3fc extent example

This is a simple demonstration of the d3fc extent component, which provides a flexible mechanism for computing the domain of a chart. It allows you to add padding, define multiple accessors, include fixed values (e.g. ensure it includes zero), etc.

var yExtent = fc.extentLinear()
	// the property of the data that defines the y extent
  .accessors([function(d) { return d.close; }])
  // pad by 10% in the +ve direction
  .pad([0, 0.1])
  // ensure that the extent includes zero
  .include([0]);

var xExtent = fc.extentDate()
	// the property of the data that defines the x extent
  .accessors([function(d) { return d.date; }])
  // pad in domain units (in this case milliseconds)
  .padUnit('domain')
  // ensure that the scale is padded by one day in either direction
  .pad([millisPerDay, millisPerDay]);

// apply the extent to the scales
x.domain(xExtent(data));
y.domain(yExtent(data));

Forked from this block: https://bl.ocks.org/d3noob/2505b09d0feb51d0c9873cc486f10f67

forked from d3noob's block: d3fc extent example