# Kibana - Bar graph with stacked counts of attributes

**URL:** <https://discuss.elastic.co/t/kibana-bar-graph-with-stacked-counts-of-attributes/202965>\
**Category:** Kibana\
**Created:** [October 10, 2019, 7:47am UTC](https://discuss.elastic.co/t/kibana-bar-graph-with-stacked-counts-of-attributes/202965 "2019-10-10T07:47:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Skeeve](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@Skeeve](https://discuss.elastic.co/u/Skeeve)\
**Post date:** [October 10, 2019, 7:47am UTC](https://discuss.elastic.co/t/kibana-bar-graph-with-stacked-counts-of-attributes/202965/1 "2019-10-10T07:47:27Z")

</div>

I also asked this on stackoverflow but Kibana questions are not often answered there it seems.

I'm puzzled as how this could be done in Kibana.

I have several records each one containing attributes. Something like this:

```auto
_id:1, a:0, b:100
_id:2, a:100, b:0
_id:3, a:100, b:100
_id:4, a:0, b:0
_id:5, a:0, b:100

```

I would like to get a stacked bar graph and I do not know how to achieve this.

It should look similar to this:

```auto
5 | XXXX XXXX X: 100
  | XXXX XXXX #: 0
3 | #### XXXX 
  | #### ####    
1 | #### ####  
  +-------------
     a b

```

I hope I could explain what I mean.

---

<div class="post-metadata">

**Author:** ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)\
**Post date:** [October 11, 2019, 12:55am UTC](https://discuss.elastic.co/t/kibana-bar-graph-with-stacked-counts-of-attributes/202965/2 "2019-10-11T00:55:46Z")

</div>

Thanks for providing some sample data to work with.

Here it is to use in Dev Tools:

```auto
PUT /discuss-202965-a
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 0
    }
  },
  "mappings": {
    "properties": {
      "a": {
        "type": "integer"
      },
      "b": {
        "type": "integer"
      }
    }
  }
}

PUT /discuss-202965-a/_doc/1
{
  "a": 0,
  "b": 100
}

PUT /discuss-202965-a/_doc/2
{
  "a": 100,
  "b": 0
}

PUT /discuss-202965-a/_doc/3
{
  "a": 100,
  "b": 100
}

PUT /discuss-202965-a/_doc/4
{
  "a": 0,
  "b": 0
}

PUT /discuss-202965-a/_doc/5
{
  "a": 0,
  "b": 100
}

```

It seems sort of backwards, but to do this you will need to select the line graph. Create two Y-axis, one to sum "a" and the other to sum "b". Then click on "Metrics & Axes" and change both Chart Type's to bar.

 ![first](https://us1.discourse-cdn.com/elastic/original/3X/7/2/728e0694f0d35e0fc60f9086db6ea201fdfb2380.png)

If you were to change the data to include the type as a field and create a document per value, we could easily split on them.

```auto
PUT /discuss-202965-b
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 0
    }
  },
  "mappings": {
    "properties": {
      "value": {
        "type": "integer"
      },
      "type": {
        "type": "keyword"
      }
    }
  }
}

POST /discuss-202965-b/_doc
{
  "value": 100,
  "type": "b"
}

POST /discuss-202965-b/_doc
{
  "value": 100,
  "type": "a"
}

POST /discuss-202965-b/_doc
{
  "value": 100,
  "type": "a"
}

POST /discuss-202965-b/_doc
{
  "value": 100,
  "type": "b"
}

POST /discuss-202965-b/_doc
{
  "value": 100,
  "type": "b"
}

```

 ![two](https://us1.discourse-cdn.com/elastic/original/3X/8/8/88af4d4c65525d8ef8a1158e8c2ad5a3a25026a1.png)

---

<div class="post-metadata">

**Author:** ![Skeeve](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@Skeeve](https://discuss.elastic.co/u/Skeeve)\
**Post date:** [October 11, 2019, 5:49am UTC](https://discuss.elastic.co/t/kibana-bar-graph-with-stacked-counts-of-attributes/202965/3 "2019-10-11T05:49:30Z")

</div>

Thanks for the nice idea. Unfortunately it's not what was asked from me ☹ The bars should contain the count of 100s and 0s of a-s and b-s. With your approach I get the sum of a-s and b-s which happen to be, in this case, similar to the count of 100s. But I'm missing the 0s.

It seems I would have to have the data in a different form than I have now in order to properly get the graphs required ☹

---

<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:** [November 8, 2019, 6:04am UTC](https://discuss.elastic.co/t/kibana-bar-graph-with-stacked-counts-of-attributes/202965/4 "2019-11-08T06:04:02Z")

</div>

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