Skip to content
Related Articles

Related Articles

D3.js stack.keys() Method

View Discussion
Improve Article
Save Article
  • Last Updated : 07 Sep, 2020

The stack.keys() method makes an array of strings as an argument and returns the stack generator.



Parameters: This method accepts a single parameter as mentioned above and described below.

  • domain: This parameter holds an array of strings as key arguments.

Return Value: This method returns the stack generator.



<!DOCTYPE html>
    <meta charset="utf-8">
    <script src=
    <h1 style="text-align: center; color: green;">
        <canvas id="gfg" width="200" height="200">
        var data = [
              {a: 3840, b: 1920, c: 960, d: 400},
              {a: 1600, b: 1440, c: 960, d: 400},
              {a:  640, b:  960, c: 640, d: 400},
              {a:  320, b:  480, c: 640, d: 400}
        var stackGen = d3.stack()
            // Defining keys
            .keys(["a", "b", "c", "d"])
        var stack = stackGen(data);
        for (i = 0; i < 4; i++) {
            // Displaying keys


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!