A small, batteries-included charting library built on D3 v7: lines, min/max and mean ±1σ bands, stacked areas, zoom, a hover crosshair, stacked/grouped bars (vertical and horizontal), heatmaps, and scatter and bubble plots, with chart width that tracks its container's rendered size. It powers the charts across this site's Weather, Sensors, EnergyPlus Weather, and Graphics sections.
Source, docs, and license: github.com/larsi-org/d3-easygraph (latest release v0.10.0, not yet on npm). ☕ If you find it useful, consider sponsoring.
Load D3 v7 (a peer dependency, not bundled), the stylesheet and the script. Under a
<script> tag the library is d3.easygraph; under a bundler it is the module's
default export. Make a chart once with a config, then call update() with data:
<div id="graph"></div>
<script src="https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js"></script>
<link rel="stylesheet" href="dist/d3.easygraph.css">
<script src="dist/d3.easygraph.min.js"></script>
<script>
var graph = d3.easygraph.line({
container: "#graph",
x: { type: "time" },
y: { preset: "temperatureC" },
height: 320
});
graph.update([ // one array per series
[ { x: new Date("2026-01-01"), y: 3 },
{ x: new Date("2026-01-02"), y: 5 },
{ x: new Date("2026-01-03"), y: 2 } ]
]);
</script>
The same ideas hold for every chart below.
x/y/
color/margin sub-objects are cloned on the way in, so one literal can build
several charts without any corrupting another. graph.update(data, domains) draws and
returns the graph, so calls chain; graph.destroy() removes the chart.update(): change it with graph.set(), then update again
(graph.set({ bands: false }).update(data)). set() checks its object like the
config and merges x, y and color key by key. It is the only
way to change a chart: assigning a key (graph.stacked = true) throws and names the
set() call to use, and the graph object is sealed, so a misspelled key cannot be added.
Live: lines, bands, stacked, voronoi,
arrows, labels, points, duration,
series, title, meta, axis label/unit/trim,
color.domain/trim.
What it is built around is fixed, and setting one throws: container,
sizing, height, width, margin, orientation,
curve, zoom, crosshair, color.palette,
color.classes, color.reverse, color.quantize, and on an axis
type, timeZone, preset, tickFormat, tickLabels; the
x, y and color objects themselves are never replaced. Destroy the
chart and build a new one to change those. Your own state goes in graph.meta.false, true or an object:
zoom: { min, max }, crosshair: { threshold, format },
voronoi: { opacity }, arrows: { color, minLength, ... },
labels: { size, offset, minZoom }, points: { radius, strokeWidth }.
bands: { minmax, sigma }, where true is both.titel,
x: { lable }, points: { radus }) or one that belongs to another chart type
(zoom on bars) throws with a suggestion, in the config and in set(). Your own
fields go under meta (copied to graph.meta).x and y are the screen axes everywhere - in the
config, in domains, in axis titles and in line and scatter points. A bar is
{ category, value } instead, either way round, so in a horizontal chart the values run
across on the x axis: that is where you pin and title them.[[{x, y}, ...], ...], a bar {category, value}); Scatter takes one flat array of points; Heatmap takes an array of
rows of numbers. A wrong shape throws a message naming the fix; an empty array is always valid.min/max/sigmaMin/sigmaMax (line bands),
color (a bar), radius, bearing + magnitude,
label, id (scatter). A point without a field renders without that feature.bandStats, a preset's convert, legendItems) return plain data and
are never called behind your back.update(data, domains) with { x, y } pins
the axis domains (data values, as in d3) for that render; Heatmap and Scatter also take
domains.color, which beats a fixed
color.domain, which beats the data's own extent. Any x/y/
color config accepts trim: [loQuantile, hiQuantile] to build a data-driven
domain from quantiles, so one outlier does not compress everything else (Weather's
"Pressure & Wind" tab clips its color scale to the 5th/95th percentile).graph.on('zoom', fn) and
graph.on('crosshair', fn) (several per event, in the order added), each called with one
object: { transform, x } for zoom (the x domain now in view), { x, pixel } for
the crosshair; on('zoom.name', fn) replaces a named listener, off() removes one.
d3.easygraph.syncZoom(graphs) and syncCrosshair(graphs) link line charts and
are themselves listeners named sync; each returns a function that undoes the link.id (see Scatter).x.$scale and x.$axis (and
the same on y, and color.$scale on Heatmap and Scatter), graph.$svg
(the chart's <svg>), graph.$plot (the <g> shifted by the
margins, holding the axes) and graph.$marks (the <g> the marks are drawn
into, and the place for your own; it is not clipped). A $ name on the graph is always one of
these; the chart's internals are on graph._, hidden and not API.d3.easygraph.presets, d3.easygraph.palettes,
d3.easygraph.formats); prefix your own names.x on a
time axis is a real Date, never shifted. Data about a place is shown in that place's zone
with x: { type: "time", timeZone: "America/New_York" }, so every viewer sees the same days
and hours; text the page writes about the same times uses
d3.easygraph.timeFormat(format, timeZone). Cutting the data into days and months is the
page's job, in the same zone, with d3.easygraph.timeZone(name) (see Line).Sizing. sizing: 'fluid' (the default, right for charts): the width
follows the container and height stays fixed; there is no width, you size the
container. sizing: 'scaled' with a logical width and
height: the chart is drawn once at that size and the browser scales the
whole <svg> uniformly through a viewBox, so its shape never changes -
for a map or any drawing with a shape of its own. In that mode scatter marks keep a
constant on-screen size. Air Traffic and Weather's Pressure & Wind
tab draw their US maps this way (960×600). graph.width/graph.height are
the whole <svg> box and plotWidth/plotHeight the plot area
inside the margins.
Titles. title is the chart's heading, blank unless you set it. Axes carry
their own titles: x.label under the horizontal axis, y.label rotated beside the
vertical one, each followed by its unit in brackets. A preset supplies both, so
y: { preset: "temperatureF" } titles the axis "Temperature [°F]" by itself. Room for an
axis title (20px) is added to your margin, reserved when the chart is built. Presets deliberately don't
supply a domain or an axis type: a sensible axis domain depends on the data, so a chart with no
pinned domains auto-scales from whatever is loaded, and an axis is linear unless it says
type: "time".
Markup. Every chart's <svg> carries class="easygraph"
(which the whole stylesheet is scoped under, so it can't restyle the surrounding page),
role="img" and an aria-label mirroring the title. Every class the library adds
starts with easygraph- and names the mark (easygraph-line,
easygraph-bar, easygraph-point, ...); that set is stable for styling and
selectors, and the full list is in the
README.
The same preset table a chart's x/y preset
resolves against is also available standalone, with no chart or container involved - handy for
e.g. converting a raw value before coloring or labeling a map marker.
d3.easygraph.preset("temperatureF");
// => { label: "Temperature", unit: "°F", convert: f(v), convertRounded: f(v, d) }
d3.easygraph.preset("temperatureF").convert(20); // => 68 (20°C to °F)
d3.easygraph.preset("temperatureF").convertRounded(20.44, 1); // => 68.8 (rounded to 1 decimal)
preset(name) returns the named preset - { label, unit, convert, convertRounded } -
or an empty one (no label, empty unit, identity convert) for a falsy name; an unrecognized
name throws, so a typo can't quietly produce a chart with no label or unit. Names are the quantity, plus
the unit where a quantity comes in several, and convert takes the quantity's base unit: temperatureC/temperatureF
(from °C), pressureHpa/pressureInHg (from hPa), rainfallMm/rainfallIn
(from mm), windSpeedMs/windSpeedKmh/windSpeedMph/windSpeedKnots (from m/s),
distanceCm/distanceIn (from cm), visibilityKm/visibilityMi (from km), and with no
conversion windDirection, relativeHumidity, solarRadiation,
clouds, uvIndex, illuminance, co2, pm25, pm10,
soilMoisture, batteryStateOfCharge, signalStrength, electricCurrent,
electricPower, electricVoltage and electricEnergy. A preset you add needs only a
label and a unit; convert is optional.
convert(v) stays unrounded, so a consumer needing full
precision isn't forced to lose it; convertRounded(v, d) rounds the result to
d decimals. A chart carries its axis preset's
convert (graph.y.convert(v)) but never applies it: the code that prepares your
data converts, with the same function the axis is labeled for. d3.easygraph.formatNumber(v)
is the axes' own number format (12.3k), for a tooltip or table that should read the same.
Preset names are fixed; a preset's label, unit text or conversion constant may still be corrected in a
minor release.
Compass labels (N, NNE, ...) for a bearing are not part of the library; the whole
compassPoint(direction, points) function is on the
Compass page to copy.
The palette resolution a chart uses for its color config is also available standalone,
for coloring something that is not an EasyGraph chart (a Leaflet marker layer, a
d3.parcoords() line). palette(name) sits beside the palettes table
the way preset(name) sits beside presets, and colorScale() takes the
same keys as a chart's color.
d3.easygraph.palette("Diverging.RdYlBu");
// => ["#a50026", "#d73027", "#f46d43", ..., "#4575b4", "#313695"]
d3.easygraph.palette("Diverging.RdYlBu", { reverse: true }); // same colors, reversed order
d3.easygraph.palette("Sequential.Blues", { classes: 4 }); // the 4-class Blues, not its largest class count
d3.easygraph.colorScale({ palette: "Diverging.RdYlBu", reverse: true, domain: [dataMin, dataMax] });
// => a ready d3.scaleLinear, clamped, with RdYlBu's colors (reversed) spread evenly across the domain
d3.easygraph.colorScale({ palette: "Sequential.Blues", domain: [dataMin, dataMax], classes: 4, quantize: true });
// => a d3.scaleQuantize instead - 4 discrete, equal-width bands rather than a continuous gradient
d3.easygraph.palette("Sequential.Turbo", { classes: 256 });
// => 256 colors sampled from d3.interpolateTurbo
Every name is Kind.Name: Sequential.* (a gradient of one quantity),
Diverging.* (a gradient with a meaningful midpoint) or Qualitative.*
(unordered, distinct categories). palette(name, { classes, reverse }) returns a plain array
of CSS colors; classes picks a class count from a Sequential or Diverging palette instead of
its largest and is ignored for a Qualitative one, which is not classed data. A scheme that exists only
as a continuous interpolator (Sequential.Turbo) is sampled at classes points,
9 by default. colorScale({ palette, domain, classes, reverse, quantize }) spreads the palette
across [min, max] as a ready color(value) scale, clamped so an out-of-range
value takes the nearest end color; quantize: true makes equal-width bands instead. It is
the scale Heatmap and Scatter build for themselves, for a caller who already knows the domain.
d3.easygraph.palettes is the { name: [colors] } table both read from; the picker
below is built from it.
Every shipped palette is an externally designed scheme:
ColorBrewer's sequential, diverging and qualitative sets
(Blues, RdYlBu, Set1, ...), Tableau's Tableau10 (the
default), Observable's Observable10, Google's Turbo and D3's
Category20/20b/20c. A palette of your own goes in
d3.easygraph.palettes under a prefix of your own: this site registers two that way in
ls-palettes.js, for Sunrise/Sunset and the
Apidae Data Grid.
In use elsewhere on the site: Weather's Comfort map markers
(colorScale({ palette: "Diverging.RdYlBu", domain: [sensor.max, sensor.min] }), hot red,
cold blue), the Apidae grid's line colors (a colorScale over its own palette) and
Strange Attractors' "color by time"
(palette("Sequential.Turbo", { classes: 256 }): its point-cloud renderer wants an array of
colors, not a scale).
The library works out what a legend needs and stops there: it never draws one.
graph.legendItems() returns plain rows for you to render however your page wants. For
Line and Bars there is one row per series, labeled from the per-series series config
([{ label, unit }, ...], in the order you pass the series to update(); a series with no label gets label: undefined,
never an invented "Series 3"). For Heatmap and Scatter the rows come from the color scale: a
color.quantize scale yields one row per band with its from/to
edges, a continuous scale one row per palette stop with its value. Labels use
d3.easygraph.formatNumber, so they read like the axis ticks. For a legend with no chart behind
it, d3.easygraph.legendItems(colors, labels) takes a color array or a palette name.
var graph = d3.easygraph.line({ container: "#graph", height: 320, lines: true,
series: [{ label: "HVAC" }, { label: "Lighting" }, { label: "Electronics" }] });
graph.legendItems();
// => [ { index: 0, color: "#4e79a7", label: "HVAC" }, ... ]
d3.select("#legend").selectAll("span").data(graph.legendItems()).join("span")
.html(d => `<span style="color:${d.color}">■</span> ${d.label}`);
d3.easygraph.legendItems(["#666", "#369", "#933"], ["Not Yet", "Visited", "Lived"]);
Live legends: Air Traffic (the four altitude bands) and States Visited (a chart-free legend).
Lines and shaded bands over a continuous (time or linear) x axis, with optional zoom (scroll to zoom, drag to pan) and a hover crosshair; several line charts on a page can share zoom and crosshair.
Gaps. A point with y: null (for the bands, min/max:
null), undefined or no y key breaks the line or band there instead of
drawing a straight segment through the hole. That is also how to chart a circular quantity such as a
compass bearing: a null point at each wraparound keeps the line from cutting across from
359° to 0°. NaN and Infinity are not gaps and are not
checked (a check per point would cost every render of a chart with tens of thousands of
points): one NaN blanks the series, one Infinity stretches the axis. Filter
them out or turn them into null first.
Bands. bands: { minmax: true } shades each series from its points'
min to max; sigma: true adds a second, darker band inside it from
sigmaMin/sigmaMax (typically the mean ±1 standard deviation). Either works
alone; the usual case is both, which bands: true says in short (try the Hourly/Daily toggle in the
examples below). The chart draws the
numbers you give it and never computes a band, so percentiles work as well. Convert min,
max, sigmaMin and sigmaMax along with y.
d3.easygraph.bandStats(values, k) returns { count, mean, min, max, sigmaMin, sigmaMax }
for an array (mean ± k population standard deviations, default 1, clamped into
[min, max]), and bandStatsFromSums({ sum, sumSq, count, min, max }, k) does the
same from running totals. This site's daily-from-hourly.js and
bucket-series.js use them: each day of EnergyPlus data is bandStats of its 24
hours.
Stacked areas. stacked: true stacks each series' plain
{ x, y } points on the ones before it. The y axis always includes zero, and the series are
combined by array index, so they must be sampled at the same x positions. Stacked areas and stacked
bars stack the same way: positive values pile up from zero and negative values down from it, each on
its own pile, so with both signs the top edge is the total of the positives and the bottom edge the
total of the negatives (generation above zero, consumption below). A series that changes sign moves
between the piles and, drawn point to point, briefly covers its neighbors there; split it into its
positive and negative parts (null elsewhere) if that matters. stacked is
true or false; anything else throws.
Series. series: [{ label, unit }, ...] describes the series in the order
you pass them to update(): label names one in the legend and the crosshair
tooltip, unit gives the tooltip its own unit on a chart that mixes quantities. A series with
no entry uses the defaults.
Events and ticks. 'zoom' listeners get { transform, x } (the x
domain now in view), 'crosshair' listeners { x, pixel } or null when
the pointer leaves. tickFormat takes a format string (".1f", "%b %d" on a
time axis), a function, or the name of an entry in d3.easygraph.formats, a table you add your own
formats to, like presets and palettes (formats.myDate = "%d.%m.%Y", or { tick, tip } when
ticks and tooltips need different forms). It ships four time formats: "date" and
"datetime" (with the time of day or not), and "date-short" and "datetime-short"
without the year, for a typical year such as an EPW file. On ticks they vary per tick at those levels, on a
24-hour clock (18:00), and a time axis with no format uses "datetime"; in a
tooltip they are 2026-03-05, 2026-03-05 14:30, 03-05 and 03-05 14:30. The crosshair tooltip has its own crosshair: { format: { x, y } },
which takes exactly the same values, e.g.
{ x: "%b %d %H:%M", y: ".1f" }. The two are separate settings and do not copy each other: ticks
are spaced, a tooltip names one point. The unit is added after it, and a side left out keeps the default
(%Y-%m-%d %H:%M for a time x, else the axes' number format).
Time zones. A time axis shows the viewer's own zone unless it names one:
timeZone: "America/New_York" (any IANA name, "UTC", or a fixed offset such as
"-05:00" for data kept in standard time all year) puts its ticks on that
zone's midnights and hours and prints its ticks and tooltip in that zone's clock, daylight saving time
included, wherever the viewer is. Positions stay real time, so the day the clocks change is 23 or 25
hours wide and nothing folds back, and the tooltip adds the zone's short name
(2026-11-18 14:00 EST). A format string or a format name follows the zone; a format
function gets the real Date and formats it itself.
d3.easygraph.timeFormat(format, timeZone) returns date => text in the same
zone, for a page's own tooltips and labels, and d3.easygraph.timeZone(name) returns the
zone itself for the page's own work in it: instant(w) turns a wall-clock date (UTC fields)
into the instant, so a month starts at instant(new Date(Date.UTC(2026, 10, 1)));
wall(t) goes the other way, for cutting readings into days; abbr(t) is
EST or EDT. The zone is fixed when the chart is built; an unknown
name, or a zone on a linear axis, throws. The weather, sensors and EPW report pages show every station
in its own time this way.
var zone = "America/New_York"; // e.g. from api/sensors/sensors' time_zone_name
var graph = d3.easygraph.line({
container: "#graph",
x: { type: "time", timeZone: zone, tickFormat: "datetime" },
height: 320,
crosshair: true
});
var tipDay = d3.easygraph.timeFormat("date", zone); // "2026-11-18", the day the axis shows
var graph = d3.easygraph.line({
container: "#graph",
x: { type: "time" },
y: { preset: "temperatureC" },
height: 320,
margin: { top: 20, right: 20, bottom: 30, left: 50 },
lines: true,
bands: true,
zoom: { min: 1, max: 50 },
crosshair: true
});
graph.update(graph_data);
// e.g. toggle daily averages (min/max band) on or off, then re-draw
graph.set({ bands: false }).update(graph_data);
// e.g. a per-sensor multi-series chart where each series has its own real-world unit,
// rather than the shared y preset's - the crosshair tooltip uses these instead
graph.set({ series: [{ unit: "°F" }, { unit: "%" }, { unit: "hPa" }] }).update(multi_sensor_data);
// e.g. switch the same three series from a plain overlapping-lines view to a stacked
// area, showing their combined total as the height of the whole stack
graph.set({ stacked: true, lines: false }).update(multi_sensor_data);
Vertical or horizontal bars, stacked or grouped. Orientation is fixed for a chart's lifetime,
but stacked vs. grouped can be toggled live (see the dropdown on the examples below). The data is
{ category, value } either way; in a horizontal chart the values run across, so
that is where the x config, domains.x and the x axis title
apply, and the category names are on y. The categories are every series' categories in
the order they first appear, and bars are matched by category, so a series may leave one out.
A bar whose datum has its own color field is drawn in it instead of the
series' palette color (the Sensitivity example). Values may be negative: the value axis includes zero
and reaches every bar, grouped bars hang from the zero line, and stacked bars pile positives up and
negatives down from it, as stacked areas do.
var graph = d3.easygraph.bar({
container: "#graph",
height: 520,
margin: { top: 10, right: 14, bottom: 30, left: 50 },
orientation: 'vertical',
stacked: false
});
// graph_data = [[{ category: "Jan", value: 3 }, { category: "Feb", value: 5 }, ...], ...]
graph.update(graph_data, { x: times });
// live toggle to stacked, then re-draw
graph.set({ stacked: true }).update(graph_data, { x: times });
A grid of colored cells over plain continuous x/y axes, for spotting patterns in a lot of data
(8,760 hourly values for a year in the example below) where a line chart would be noise.
update() takes an array of rows of numbers, row 0 at the bottom; with no pinned domains
the axes span the grid's own size (x: [0, columns], y: [0, rows]), so ticks
line up with cell edges. A null or undefined cell has no
data: it is drawn empty (class easygraph-heatmap-cell-missing, restyle it for a "no data"
color) and left out of the color range. The default palette is Diverging.RdBu reversed (blue low, red
high), since categorical hues make no sense on a gradient; color: { reverse: false } keeps
RdBu the other way round, and a palette you name is reversed only with reverse: true.
color also takes a fixed domain or a trim.
var graph = d3.easygraph.heatmap({
container: "#graph",
x: { type: "time" },
height: 520,
margin: { top: 10, right: 14, bottom: 30, left: 50 }
});
graph.update(graph_data, { x: [ startDate, endDate ], y: [ 0, 24 ] });
// switch to a different data channel, then re-draw
graph.update(otherGraphData, { x: [ startDate, endDate ], y: [ 0, 24 ] });
Colored circles at arbitrary { x, y, value } points over plain continuous x/y axes,
value colored through the color scale. No geography is built in: to overlay a
map, project each point's lat/lng to pixels yourself (e.g. with d3.geoAlbersUsa()), draw
the base map separately and hand scatter the projected coordinates, as
Weather's "Pressure & Wind" tab and Air Traffic
do.
points draws a circle per point ({ radius, strokeWidth },
defaults 4 and 0.5); points: false draws none, for a picture of only arrows, labels or
voronoi cells. A point's own radius overrides points.radius, which makes a
bubble chart.voronoi: true fills the region closer to each point than to any other
with that point's color, semi-transparent (voronoi: { opacity }, default 0.6) so a base map
shows through.arrows: true draws a shaft with a chevron head on every point that
also has bearing (compass degrees, 0 = north, clockwise; the arrow points toward it) and
magnitude: a vector quantity (wind) over a scalar one (pressure, the color). Length runs
from arrows.minLength to maxLength (6 and 24).labels: true draws each point's label above-right of it;
labels: { minZoom } hides them below that zoom factor (Air Traffic labels its ~6,000
aircraft only once zoomed in).color takes a fixed domain: [min, max], which beats the data's
extent and trim, so a value keeps its color from snapshot to snapshot.
quantize: true makes equal-width bands instead of a gradient: Air Traffic colors altitude
with { domain: [0, 40000], quantize: true, palette: "Sequential.Blues", classes: 4 }, so
cruise altitude reads as one dark band.id joins a point to its circle from one update() to the
next (array position only for a point without one). When the set of points can grow, shrink or
reorder (Weather drops stations with no reading for the hour), give every point an id, or
circles are rebound to other points and fly across the map. A label is only drawn text.graph.zoomScale(k) tells the chart the zoom factor: it divides
marker radius, arrow length, stroke widths and label size by k and draws again, for a caller zooming the chart with its own SVG
transform (both map pages), so markers keep their size on screen.
var graph = d3.easygraph.scatter({
container: "#graph",
x: { type: "linear" },
y: { type: "linear" },
color: { domain: [0, 40000], quantize: true, palette: "Sequential.Blues", classes: 4 },
height: 320,
margin: { top: 20, right: 20, bottom: 30, left: 50 }
});
var graph = d3.easygraph.scatter({
container: "#graph",
x: { type: "linear" },
y: { type: "linear" },
color: { palette: "Diverging.RdBu", reverse: true, trim: [0.05, 0.95] },
height: 320,
margin: { top: 20, right: 20, bottom: 30, left: 50 },
voronoi: true,
arrows: true,
labels: true
});
// each point can carry an optional bearing (degrees) + magnitude for the arrows layer and an
// optional label, alongside the value that drives its circle's color
graph.update(points, { x: [0, 10], y: [0, 10] });
// layering the chart under an external zoom transform (e.g. panning/zooming a map underneath)?
// call this on every zoom event so markers stay a constant size instead of scaling with it
graph.zoomScale(event.transform.k);
Small self-contained examples (Weather and Air Traffic, above, are the real map overlays):