# Using stacked bar charts

**URL:** <https://discuss.elastic.co/t/using-stacked-bar-charts/97541>\
**Category:** Kibana\
**Created:** [August 18, 2017, 8:57am UTC](https://discuss.elastic.co/t/using-stacked-bar-charts/97541 "2017-08-18T08:57:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudhanva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sudhanva/32/21250_2.png) [@sudhanva](https://discuss.elastic.co/u/sudhanva)\
**Post date:** [August 18, 2017, 8:57am UTC](https://discuss.elastic.co/t/using-stacked-bar-charts/97541/1 "2017-08-18T08:57:56Z")

</div>

I have data in JSON format like this in my elasticsearch:

```
{
    "features": [
          {
            "feature": "A",
            "Yes": 19,
            "No": 0,
            "Maybe": 81
          },
          {
            "feature": "B",
            "Yes": 0,
            "No": 0,
            "Maybe": 100
          },
          {
            "feature": "C",
            "Yes": 10,
            "No": 32,
            "Maybe": 58
          }
        ]
    }

```

From this, is it possible to obtain a stacked chart as follows?  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/0/70d2e0c9f8adc92c509c66789627d02a89ec1451.png)

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [August 18, 2017, 7:29pm UTC](https://discuss.elastic.co/t/using-stacked-bar-charts/97541/2 "2017-08-18T19:29:10Z")

</div>

Hi,

Unfortunately, that data format is a nested datatype, which isn't supported in Kibana right now.

Regardless, since Kibana uses aggregations to visualize data, you will have to store the data as separate documents, such as:

```auto
POST /stackedtest/doc
{
  "feature": "A",
  "response": "Yes",
  "count": 19
}
POST /stackedtest/doc
{
  "feature": "A",
  "response": "No",
  "count": 0
}
POST /stackedtest/doc
{
  "feature": "A",
  "response": "Maybe",
  "count": 81
}
POST /stackedtest/doc
{
  "feature": "B",
  "response": "Yes",
  "count": 0
}
POST /stackedtest/doc
{
  "feature": "B",
  "response": "No",
  "count": 0
}
POST /stackedtest/doc
{
  "feature": "B",
  "response": "Maybe",
  "count": 100
}
POST /stackedtest/doc
{
  "feature": "C",
  "response": "Yes",
  "count": 10
}
POST /stackedtest/doc
{
  "feature": "C",
  "response": "No",
  "count": 32
}
POST /stackedtest/doc
{
  "feature": "C",
  "response": "Maybe",
  "count": 58
}

```

Then you can build a stacked bar where the X-Axis is a filters aggregation, the Y-Axis is split using a terms aggregation of the response, and the Y-Axis metric is a max of the response count for the term:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/c/1c2b9837dfead464da11ecc24fd8ae7c53ba6632.png)

---

<div class="post-metadata">

**Author:** ![sudhanva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sudhanva/32/21250_2.png) [@sudhanva](https://discuss.elastic.co/u/sudhanva)\
**Post date:** [August 22, 2017, 6:11am UTC](https://discuss.elastic.co/t/using-stacked-bar-charts/97541/3 "2017-08-22T06:11:58Z")

</div>

This was very helpul! Thanks a lot 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 19, 2017, 6:12am UTC](https://discuss.elastic.co/t/using-stacked-bar-charts/97541/4 "2017-09-19T06:12:25Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
