The D3.js stackOrderOffsetExpand() method applies a zero baseline and normalizes the values for each point such that the topline is always one.
Syntax:
d3.stackOrderOffsetExpand(series, order);
Parameters: This function accepts two parameters as mentioned above and described below.
- series: This is the series based on which offset is expanded.
- order: This is the ordering of the stack.
Return Value: This method returns no value.
Example:
HTML
<!DOCTYPE html> < html >
< head >
< meta charset = "utf-8" >
< script src =
</ script >
</ head >
< body >
< h1 style = "text-align: center; color: green;" >
GeeksforGeeks
</ h1 >
< script >
var data = [
{letter: {a: 1000, b: 2000, c: 3000, d: 4000}},
{letter: {a: 2000, b: 3000, c: 4000, d: 5000}},
{letter: {a: 640, b: 960, c: 640, d: 400}},
{letter: {a: 320, b: 480, c: 640, d: 400}}
];
var stack = d3.stack()
.keys(["a", "b", "c", "d"])
.value((d, key) => d.letter[key])
.order(d3.stackOrderNone)
// Use of d3.stackOrderOffsetExpand() Method
.offset(d3.stackOffsetExpand);
var series = stack(data);
console.log(series);
</ script >
</ body >
</ html >
|
Output: