# Pie Chart metric slice size

**URL:** <https://discuss.elastic.co/t/pie-chart-metric-slice-size/135567>\
**Category:** Kibana\
**Created:** [June 12, 2018, 3:47pm UTC](https://discuss.elastic.co/t/pie-chart-metric-slice-size/135567 "2018-06-12T15:47:50Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![pqt120583](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@pqt120583](https://discuss.elastic.co/u/pqt120583)\
**Post date:** [June 12, 2018, 3:47pm UTC](https://discuss.elastic.co/t/pie-chart-metric-slice-size/135567/1 "2018-06-12T15:47:50Z")

</div>

Hi all,

I have trouble to create chart with "Metric - Slice size". I want to use the count aggregate with a specific property ( like unique count) but there's no options for it.

ex: I have list of records like below:

```
    [
            {"category": "A", "amount": 28 , { "customer_Id" : 1}},
            {"category": "A", "amount": 12, { "customer_Id" : 2}},
            {"category": "A", "amount": 18, { "customer_Id" : 2}},
            {"category": "B", "amount": 55, { "customer_Id" : 5}},
            {"category": "C", "amount": 43, { "customer_Id" : 3}},
            {"category": "D", "amount": 91, { "customer_Id" : 4}} ,
            {"category": "D", "amount": 31, { "customer_Id" : 5}}           
     ]

```

I want to create a pie chart which is splitted by category and count on the number of customer.

But I don't know how to create it. Can someone help to guide me ?

Thanks,  
Thomas.

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [June 12, 2018, 3:56pm UTC](https://discuss.elastic.co/t/pie-chart-metric-slice-size/135567/2 "2018-06-12T15:56:05Z")

</div>

Hi Thomas,

just to make sure I am understanding you right, you would like the above data to produce 4 slices (one for A, B, C and D and give each the size in relation to the amount of different "customer\_id" values they had?

If so you can easily create a pie chart, and Use "Terms" aggregation on category for the "Split Slice" bucket, and on the metrics side select "Unique Count" on that customer id field.

Cheers,  
Tim

---

<div class="post-metadata">

**Author:** ![pqt120583](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@pqt120583](https://discuss.elastic.co/u/pqt120583)\
**Post date:** [June 12, 2018, 4:23pm UTC](https://discuss.elastic.co/t/pie-chart-metric-slice-size/135567/3 "2018-06-12T16:23:14Z")

</div>

Thank Timroes,

But I want to use count instead of unique count because i want to know exactly how many times customer select a category.

Is there a way to resolve this ?

many thanks,  
Thomas.

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [June 12, 2018, 5:01pm UTC](https://discuss.elastic.co/t/pie-chart-metric-slice-size/135567/4 "2018-06-12T17:01:21Z")

</div>

Could you perhaps provide for the example data above which slices you actually want to have in the pie, and which values should be attached to that slices, since I unfortunately don't understand exactly which order you want to have. Because if you want to see how many times a customer selects a category, that sounds more like you want the customer on the slice level?

---

<div class="post-metadata">

**Author:** ![pqt120583](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@pqt120583](https://discuss.elastic.co/u/pqt120583)\
**Post date:** [June 12, 2018, 5:17pm UTC](https://discuss.elastic.co/t/pie-chart-metric-slice-size/135567/5 "2018-06-12T17:17:49Z")

</div>

The pie chart will have 4 slice (A, B, C , D) :

- A has value 3
- B has value 1
- C has value 1
- D has value 2

The value of each slice is counted by customer Id.

Here is the data :

```
[
            {"category": "A", "amount": 28 , { "customer_Id" : 1}},
            {"category": "A", "amount": 12, { "customer_Id" : 2}},
            {"category": "A", "amount": 18, { "customer_Id" : 2}},
            {"category": "A", "amount": 18},
            {"category": "B", "amount": 55, { "customer_Id" : 5}},
            {"category": "C", "amount": 43, { "customer_Id" : 3}},
            {"category": "D", "amount": 91, { "customer_Id" : 4}} ,
            {"category": "D", "amount": 31, { "customer_Id" : 5}}           
     ]
```

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [June 12, 2018, 5:25pm UTC](https://discuss.elastic.co/t/pie-chart-metric-slice-size/135567/6 "2018-06-12T17:25:25Z")

</div>

Oh in this case, you just leave the metric aggregation to "Count" (it's default value). That way it will just use the count of individual documents.

---

<div class="post-metadata">

**Author:** ![pqt120583](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@pqt120583](https://discuss.elastic.co/u/pqt120583)\
**Post date:** [June 13, 2018, 3:07am UTC](https://discuss.elastic.co/t/pie-chart-metric-slice-size/135567/7 "2018-06-13T03:07:59Z")

</div>

Sorry Timroes, I have updated the data, some of the records will not have the object containning customerId.

If I use count , it use the doc\_count not the count of customer appearrance.

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [June 13, 2018, 3:22pm UTC](https://discuss.elastic.co/t/pie-chart-metric-slice-size/135567/8 "2018-06-13T15:22:44Z")

</div>

In this case you could still use count, but just add a filter to the visualization, for `customer_id` `exists`. That way you will filter out all documents before aggregating, that doesn't have the customer\_id field!

Cheers,  
Tim

---

<div class="post-metadata">

**Author:** ![pqt120583](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@pqt120583](https://discuss.elastic.co/u/pqt120583)\
**Post date:** [June 14, 2018, 4:01am UTC](https://discuss.elastic.co/t/pie-chart-metric-slice-size/135567/9 "2018-06-14T04:01:59Z")

</div>

The problem is that I don't know where to add the filter. Can you please help to create one simple sample with pie chart ?

Many thanks,  
Thomas.

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [June 14, 2018, 7:29am UTC](https://discuss.elastic.co/t/pie-chart-metric-slice-size/135567/10 "2018-06-14T07:29:16Z")

</div>

Hi,

just use the "Add Filter" button on the top of your screen (below the query bar):

![screenshot-20180614-092808](https://us1.discourse-cdn.com/elastic/original/3X/9/2/92010763f6286ccc1fc3522674801ccf97948510.png)

Then select the `customer_id` field, that you want to be present, and use as an Operator "exists".

That way the data of the visualization will be filtered down and saved with that visualization.

Cheers,  
Tim

---

<div class="post-metadata">

**Author:** ![pqt120583](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@pqt120583](https://discuss.elastic.co/u/pqt120583)\
**Post date:** [June 15, 2018, 5:45am UTC](https://discuss.elastic.co/t/pie-chart-metric-slice-size/135567/11 "2018-06-15T05:45:10Z")

</div>

Thank Timrose, It resolves my problem.

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [June 15, 2018, 11:07am UTC](https://discuss.elastic.co/t/pie-chart-metric-slice-size/135567/12 "2018-06-15T11:07:44Z")

</div>

I'm glad we could solve it that easily. Please always feel free to come back with further questions (ideally in new threads, if they are about different topics).

Have a nice weekend ☀

---

<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:** [July 13, 2018, 11:07am UTC](https://discuss.elastic.co/t/pie-chart-metric-slice-size/135567/13 "2018-07-13T11:07:47Z")

</div>

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