D3 API Reference
D3 is a collection of modules that are designed to work together; you can use the modules independently, or you can use them together as part of the default build. The source and documentation for each module is available in its repository. Follow the links below to learn more. For changes between major versions, see CHANGES; see also the release notes and the 3.x reference.
-
Arrays (Statistics, Search, Transformations, Histograms)
- Axes
- Brushes
- Chords
-
Collections (Objects, Maps, Sets, Nests)
- Colors
- Color Schemes
- Contours
- Dispatches
- Dragging
- Delimiter-Separated Values
- Easings
- Fetches
- Forces
- Number Formats
-
Geographies (Paths, Projections, Spherical Math, Spherical Shapes, Streams, Transforms)
- Hierarchies
- Interpolators
- Paths
- Polygons
- Quadtrees
- Random Numbers
-
Scales (Continuous, Sequential, Diverging, Quantize, Ordinal)
-
Selections (Selecting, Modifying, Data, Events, Control, Local Variables, Namespaces)
-
Shapes (Arcs, Pies, Lines, Areas, Curves, Links, Symbols, Stacks)
- Time Formats
- Time Intervals
- Timers
- Transitions
- Voronoi Diagrams
- Zooming
D3 uses semantic versioning. The current version is exposed as d3.version.
Array manipulation, ordering, searching, summarizing, etc.
Methods for computing basic summary statistics.
-
d3.min - compute the minimum value in an array.
-
d3.max - compute the maximum value in an array.
-
d3.extent - compute the minimum and maximum value in an array.
-
d3.sum - compute the sum of an array of numbers.
-
d3.mean - compute the arithmetic mean of an array of numbers.
-
d3.median - compute the median of an array of numbers (the 0.5-quantile).
-
d3.quantile - compute a quantile for a sorted array of numbers.
-
d3.variance - compute the variance of an array of numbers.
-
d3.deviation - compute the standard deviation of an array of numbers.
Methods for searching arrays for a specific element.
Methods for transforming arrays and for generating new arrays.
-
d3.cross - compute the Cartesian product of two arrays.
-
d3.merge - merge multiple arrays into one array.
-
d3.pairs - create an array of adjacent pairs of elements.
-
d3.permute - reorder an array of elements according to an array of indexes.
-
d3.shuffle - randomize the order of an array.
-
d3.ticks - generate representative values from a numeric interval.
-
d3.tickIncrement - generate representative values from a numeric interval.
-
d3.tickStep - generate representative values from a numeric interval.
-
d3.range - generate a range of numeric values.
-
d3.transpose - transpose an array of arrays.
-
d3.zip - transpose a variable number of arrays.
Bin discrete samples into continuous, non-overlapping intervals.
Human-readable reference marks for scales.
Select a one- or two-dimensional region using the mouse or touch.
Handy data structures for elements keyed by string.
Methods for converting associative arrays (objects) to arrays.
-
d3.keys - list the keys of an associative array.
-
d3.values - list the values of an associated array.
-
d3.entries - list the key-value entries of an associative array.
Like ES6 Map, but with string keys and a few other differences.
-
d3.map - create a new, empty map.
-
map.has - returns true if the map contains the given key.
-
map.get - get the value for the given key.
-
map.set - set the value for the given key.
-
map.remove - remove the entry for given key.
-
map.clear - remove all entries.
-
map.keys - get the array of keys.
-
map.values - get the array of values.
-
map.entries - get the array of entries (key-values objects).
-
map.each - call a function for each entry.
-
map.empty - returns false if the map has at least one entry.
-
map.size - compute the number of entries.
Like ES6 Set, but with string keys and a few other differences.
-
d3.set - create a new, empty set.
-
set.has - returns true if the set contains the given value.
-
set.add - add the given value.
-
set.remove - remove the given value.
-
set.clear - remove all values.
-
set.values - get the array of values.
-
set.each - call a function for each value.
-
set.empty - returns true if the set has at least one value.
-
set.size - compute the number of values.
Group data into arbitrary hierarchies.
-
d3.nest - create a new nest generator.
-
nest.key - add a level to the nest hierarchy.
-
nest.sortKeys - sort the current nest level by key.
-
nest.sortValues - sort the leaf nest level by value.
-
nest.rollup - specify a rollup function for leaf values.
-
nest.map - generate the nest, returning a map.
-
nest.object - generate the nest, returning an associative array.
-
nest.entries - generate the nest, returning an array of key-values tuples.
Color manipulation and color space conversion.
-
d3.color - parse the given CSS color specifier.
-
color.rgb - compute the RGB equivalent of this color.
-
color.brighter - create a brighter copy of this color.
-
color.darker - create a darker copy of this color.
-
color.displayable - returns true if the color is displayable on standard hardware.
-
color.hex - returns the hexadecimal RGB string representation of this color.
-
color.toString - returns the RGB string representation of this color.
-
d3.rgb - create a new RGB color.
-
d3.hsl - create a new HSL color.
-
d3.lab - create a new Lab color.
-
d3.hcl - create a new HCL color.
-
d3.lch - create a new HCL color.
-
d3.gray - create a new Lab gray.
-
d3.cubehelix - create a new Cubehelix color.
Color ramps and palettes for quantitative, ordinal and categorical scales.
Categorical
Diverging
Sequential (Single Hue)
Sequential (Multi-Hue)
Cyclical
Compute contour polygons using marching squares.
Separate concerns using named callbacks.
Drag and drop SVG, HTML or Canvas using mouse or touch input.
Parse and format delimiter-separated values, most commonly CSV and TSV.
Easing functions for smooth animation.
Convenience methods on top of the Fetch API.
-
d3.blob - get a file as a blob.
-
d3.buffer - get a file as an array buffer.
-
d3.csv - get a comma-separated values (CSV) file.
-
d3.dsv - get a delimiter-separated values (CSV) file.
-
d3.image - get an image.
-
d3.json - get a JSON file.
-
d3.text - get a plain text file.
-
d3.tsv - get a tab-separated values (TSV) file.
Force-directed graph layout using velocity Verlet integration.
Format numbers for human consumption.
Geographic projections, shapes and math.
-
d3.geoPath - create a new geographic path generator.
-
path - project and render the specified feature.
-
path.area - compute the projected planar area of a given feature.
-
path.bounds - compute the projected planar bounding box of a given feature.
-
path.centroid - compute the projected planar centroid of a given feature.
-
path.measure - compute the projected planar length of a given feature.
-
path.projection - set the geographic projection.
-
path.context - set the render context.
-
path.pointRadius - set the radius to display point features.
-
d3.geoArea - compute the spherical area of a given feature.
-
d3.geoBounds - compute the latitude-longitude bounding box for a given feature.
-
d3.geoCentroid - compute the spherical centroid of a given feature.
-
d3.geoContains - test whether a point is inside a given feature.
-
d3.geoDistance - compute the great-arc distance between two points.
-
d3.geoLength - compute the length of a line string or the perimeter of a polygon.
-
d3.geoInterpolate - interpolate between two points along a great arc.
-
d3.geoRotation - create a rotation function for the specified angles.
-
rotation - rotate the given point around the sphere.
-
rotation.invert - unrotate the given point around the sphere.
Layout algorithms for visualizing hierarchical data.
Interpolate numbers, colors, strings, arrays, objects, whatever!
Serialize Canvas path commands to SVG.
Geometric operations for two-dimensional polygons.
Two-dimensional recursive spatial subdivision.
Generate random numbers from various distributions.
Encodings that map abstract data to visual representation.
Map a continuous, quantitative domain to a continuous range.
Map a continuous, quantitative domain to a continuous, fixed interpolator.
Map a continuous, quantitative domain to a continuous, fixed interpolator.
Map a continuous, quantitative domain to a discrete range.
Map a discrete domain to a discrete range.
Transform the DOM by selecting elements and joining to data.
Graphical primitives for visualization.
Circular or annular sectors, as in a pie or donut chart.
Compute the necessary angles to represent a tabular dataset as a pie or donut chart.
A spline or polyline, as in a line chart.
An area, defined by a bounding topline and baseline, as in an area chart.
Interpolate between points to produce a continuous shape.
A smooth cubic Bézier curve from a source to a target.
A categorical shape encoding, as in a scatterplot.
Stack shapes, placing one adjacent to another, as in a stacked bar chart.
Parse and format times, inspired by strptime and strftime.
A calculator for humanity’s peculiar conventions of time.
-
d3.timeInterval - implement a new custom time interval.
-
interval - alias for interval.floor.
-
interval.floor - round down to the nearest boundary.
-
interval.round - round to the nearest boundary.
-
interval.ceil - round up to the nearest boundary.
-
interval.offset - offset a date by some number of intervals.
-
interval.range - generate a range of dates at interval boundaries.
-
interval.filter - create a filtered subset of this interval.
-
interval.every - create a filtered subset of this interval.
-
interval.count - count interval boundaries between two dates.
-
d3.timeMillisecond, d3.utcMillisecond - the millisecond interval.
-
d3.timeMilliseconds, d3.utcMilliseconds - aliases for millisecond.range.
-
d3.timeSecond, d3.utcSecond - the second interval.
-
d3.timeSeconds, d3.utcSeconds - aliases for second.range.
-
d3.timeMinute, d3.utcMinute - the minute interval.
-
d3.timeMinutes, d3.utcMinutes - aliases for minute.range.
-
d3.timeHour, d3.utcHour - the hour interval.
-
d3.timeHours, d3.utcHours - aliases for hour.range.
-
d3.timeDay, d3.utcDay - the day interval.
-
d3.timeDays, d3.utcDays - aliases for day.range.
-
d3.timeWeek, d3.utcWeek - aliases for sunday.
-
d3.timeWeeks, d3.utcWeeks - aliases for week.range.
-
d3.timeSunday, d3.utcSunday - the week interval, starting on Sunday.
-
d3.timeSundays, d3.utcSundays - aliases for sunday.range.
-
d3.timeMonday, d3.utcMonday - the week interval, starting on Monday.
-
d3.timeMondays, d3.utcMondays - aliases for monday.range.
-
d3.timeTuesday, d3.utcTuesday - the week interval, starting on Tuesday.
-
d3.timeTuesdays, d3.utcTuesdays - aliases for tuesday.range.
-
d3.timeWednesday, d3.utcWednesday - the week interval, starting on Wednesday.
-
d3.timeWednesdays, d3.utcWednesdays - aliases for wednesday.range.
-
d3.timeThursday, d3.utcThursday - the week interval, starting on Thursday.
-
d3.timeThursdays, d3.utcThursdays - aliases for thursday.range.
-
d3.timeFriday, d3.utcFriday - the week interval, starting on Friday.
-
d3.timeFridays, d3.utcFridays - aliases for friday.range.
-
d3.timeSaturday, d3.utcSaturday - the week interval, starting on Saturday.
-
d3.timeSaturdays, d3.utcSaturdays - aliases for saturday.range.
-
d3.timeMonth, d3.utcMonth - the month interval.
-
d3.timeMonths, d3.utcMonths - aliases for month.range.
-
d3.timeYear, d3.utcYear - the year interval.
-
d3.timeYears, d3.utcYears - aliases for year.range.
An efficient queue for managing thousands of concurrent animations.
-
d3.now - get the current high-resolution time.
-
d3.timer - schedule a new timer.
-
timer.restart - reset the timer’s start time and callback.
-
timer.stop - stop the timer.
-
d3.timerFlush - immediately execute any eligible timers.
-
d3.timeout - schedule a timer that stops on its first callback.
-
d3.interval - schedule a timer that is called with a configurable period.
Animated transitions for selections.
Compute the Voronoi diagram of a given set of points.
Pan and zoom SVG, HTML or Canvas using mouse or touch input.