Generates a stack for the given array of data, returning an array representing each series. The resulting array has one element per series. Each series in then typically passed to an area generator to render an area chart, or used to construct rectangles for a bar chart.
Any additional arguments are arbitrary; they are simply propagated to the generator’s accessor functions along with the this object.
Array of data elements.
Rest
...args: any[]Returns the current keys accessor, which defaults to the empty array.
Returns the current keys accessor, which defaults to the empty array.
Rest
...args: any[]Sets the keys accessor to the specified function or array and returns this stack generator. A series (layer) is generated for each key. Keys are typically strings, but they may be arbitrary values. The series’ key is passed to the value accessor, along with each data point, to compute the point’s value.
Returns the current offset accessor, which defaults to stackOffsetNone; this uses a zero baseline.
Returns the current offset accessor, which defaults to stackOffsetNone; this uses a zero baseline.
Reset the offset to use stackOffsetNone; this uses a zero baseline.
null to set to the default stackOffsetNone.
Sets the offset accessor to the specified function and returns this stack generator.
A function which is passed the generated series array and the order index array; it is then responsible for updating the lower and upper values in the series array.
Returns the current order accessor, which defaults to stackOrderNone; this uses the order given by the key accessor.
Returns the current order accessor, which defaults to stackOrderNone; this uses the order given by the key accessor.
Sets the order accessor to the specified array and returns this stack generator.
Sets the order accessor to the specified function and returns this stack generator.
The stack order is computed prior to the offset; thus, the lower value for all points is zero at the time the order is computed. The index attribute for each series is also not set until after the order is computed.
See stack orders for the built-in orders.
A function returning a sort order array. It is passed the generated series array and must return an array of numeric indexes representing the stack order.
Returns the current value accessor, which defaults to a function return the property corresponding to the relevant key from the data element.
Thus, by default the stack generator assumes that the input data is an array of objects, with each object exposing named properties with numeric values; see stack for an example.
Returns the current value accessor, which defaults to a function return the property corresponding to the relevant key from the data element.
Thus, by default the stack generator assumes that the input data is an array of objects, with each object exposing named properties with numeric values; see stack for an example.
Sets the value accessor to the specified number and returns this stack generator.
A constant value.
Sets the value accessor to the specified function and returns this stack generator.
A value accessor function which returns the numeric value for a given data element and key combination. The accessor function is invoked for each data element and key being passed the datum, the key, index of the data element in the input data array, and the complete data array.
A stack generator.
Some shape types can be stacked, placing one shape adjacent to another. For example, a bar chart of monthly sales might be broken down into a multi-series bar chart by product category, stacking bars vertically. This is equivalent to subdividing a bar chart by an ordinal dimension (such as product category) and applying a color encoding.
Stacked charts can show overall value and per-category value simultaneously; however, it is typically harder to compare across categories, as only the bottom layer of the stack is aligned. So, chose the stack order carefully, and consider a streamgraph. (See also grouped charts.)
Like the pie generator, the stack generator does not produce a shape directly. Instead it computes positions which you can then pass to an area generator or use directly, say to position bars.
The first generic corresponds to the "this" context in which the stack generator and its accessor functions are invoked.
The second generic corresponds to the data type of an element in the data array passed into the stack generator.
The third generic corresponds to the data type of key used to identify a series.