# How to draw pie chart with sum of two columns

**URL:** <https://discuss.elastic.co/t/how-to-draw-pie-chart-with-sum-of-two-columns/127060>\
**Category:** Kibana\
**Created:** [April 6, 2018, 9:39am UTC](https://discuss.elastic.co/t/how-to-draw-pie-chart-with-sum-of-two-columns/127060 "2018-04-06T09:39:01Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dyl](https://avatars.discourse-cdn.com/v4/letter/d/5fc32e/32.png) [@dyl](https://discuss.elastic.co/u/dyl)\
**Post date:** [April 6, 2018, 9:39am UTC](https://discuss.elastic.co/t/how-to-draw-pie-chart-with-sum-of-two-columns/127060/1 "2018-04-06T09:39:02Z")

</div>

Hey guys !

I've got a CSV which is imported into elasticsearch. It looks like :

```
day;brushing;haircut;waxing hair removal;makeup
Monday;150;350;0;50
Tuesday;130;450;0;120
Wednesday;40;250;60;120
Thursday;78;150;80;0
Friday;65;120;70;50
Sunday;250;540;130;90

```

And thanks to Kibana I want to do a pie chart which represent the repartition between (sum of haircut + sum of brushing) and (sum of waxing hair removal + sum of makeup).

Here :

- Sum of brushing : 713.

- Sum of haircut : 1860.

- **Sum of these two values : 2573. (76.97%)**.

- Sum of waxing hair removal :340.

- Sum of makeup : 430

- **Sum of these two values : 770 (23.03%)**.

And now I want a graph with these two bold values like this example :  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/8/c816038fb80c11025104913e535d110bc6fe8487.png)

Could you help me ? I Can't draw my pie chart ..

Ps : With metric, I just succed to have "2573" and "770" with :

Sum aggregation and JSON input : {"script" : "doc['brushing'].value + doc['haircut'].value"}  
and  
Sum aggregation and JSON input : {"script" : "doc['waxing hair removal'].value + doc['makeup'].value"}

But i'm still unable to have these two values on my pie chart

---

<div class="post-metadata">

**Author:** ![Bargs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bargs/32/5429_2.png) [@Bargs](https://discuss.elastic.co/u/Bargs)\
**Post date:** [April 6, 2018, 10:41pm UTC](https://discuss.elastic.co/t/how-to-draw-pie-chart-with-sum-of-two-columns/127060/3 "2018-04-06T22:41:46Z")

</div>

The splits in a pie chart are based on elasticsearch bucket aggregations, so each split is based on a group of documents. In order to split the pie chart the way you want, you need a way to slice up and group your documents based on the type of service that was provided. There's no way to split a pie chart on multiple metrics that are based on the same underlying group of documents.

You'd have more flexibility if you structure your data model a little differently. Try splitting each line item into its own document, so each document looks something like this:

```auto
{
  day: "Monday",
  service: "brushing",
  total: 150
}

{
  day: "Monday",
  service: "haircut",
  total: 350
}

{
  day: "Monday",
  service: "waxing hair removal",
  total: 0
}

... etc

```

Now, in your pie chart configuration you can do a filters aggregation. For one filter do `service:(brushing OR haircut)` and for the other do `service:("waxing hair removal" OR makeup)`. Now you've got two buckets, one with documents representing hairdressing benefits, the other representing aesthetic benefits. Now in the metrics section of the pie chart configuration you just need to do a sum on the total field. That should generate the visualization you're looking for!

---

<div class="post-metadata">

**Author:** ![dyl](https://avatars.discourse-cdn.com/v4/letter/d/5fc32e/32.png) [@dyl](https://discuss.elastic.co/u/dyl)\
**Post date:** [April 11, 2018, 6:12am UTC](https://discuss.elastic.co/t/how-to-draw-pie-chart-with-sum-of-two-columns/127060/4 "2018-04-11T06:12:34Z")

</div>

Hey Bargs 🙂

Ok I'll try it asap and i'll tell u if I got problems

Thx for answer !

---

<div class="post-metadata">

**Author:** ![dyl](https://avatars.discourse-cdn.com/v4/letter/d/5fc32e/32.png) [@dyl](https://discuss.elastic.co/u/dyl)\
**Post date:** [April 23, 2018, 7:25am UTC](https://discuss.elastic.co/t/how-to-draw-pie-chart-with-sum-of-two-columns/127060/5 "2018-04-23T07:25:07Z")

</div>

I have just returned to work on this project and I do not understand where I need to modify my document to obtain:

> {  
> day: "Monday",  
> service: "brushing",  
> total: 150  
> }

Directly in my logstash pipeline or elsewhere ?

Thx

---

<div class="post-metadata">

**Author:** ![dyl](https://avatars.discourse-cdn.com/v4/letter/d/5fc32e/32.png) [@dyl](https://discuss.elastic.co/u/dyl)\
**Post date:** [April 24, 2018, 9:07am UTC](https://discuss.elastic.co/t/how-to-draw-pie-chart-with-sum-of-two-columns/127060/6 "2018-04-24T09:07:46Z")

</div>

I up this topic cause I really need help about that 🙂

Thank you in advance @Bargs

---

<div class="post-metadata">

**Author:** ![Bargs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bargs/32/5429_2.png) [@Bargs](https://discuss.elastic.co/u/Bargs)\
**Post date:** [April 26, 2018, 9:51pm UTC](https://discuss.elastic.co/t/how-to-draw-pie-chart-with-sum-of-two-columns/127060/7 "2018-04-26T21:51:23Z")

</div>

Since your data is just coming from a CSV, I would write a script or use a spreadsheet application or something like that to get the CSV into the required format before ingesting into ES.

---

<div class="post-metadata">

**Author:** ![dyl](https://avatars.discourse-cdn.com/v4/letter/d/5fc32e/32.png) [@dyl](https://discuss.elastic.co/u/dyl)\
**Post date:** [April 27, 2018, 8:41am UTC](https://discuss.elastic.co/t/how-to-draw-pie-chart-with-sum-of-two-columns/127060/8 "2018-04-27T08:41:50Z")

</div>

But what do you mean about "required format" ?

---

<div class="post-metadata">

**Author:** ![Bargs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bargs/32/5429_2.png) [@Bargs](https://discuss.elastic.co/u/Bargs)\
**Post date:** [April 27, 2018, 10:06pm UTC](https://discuss.elastic.co/t/how-to-draw-pie-chart-with-sum-of-two-columns/127060/9 "2018-04-27T22:06:16Z")

</div>

The format I described in my first post. You'd transform your csv so that it has three columns, `day`, `service`, and `total`.

---

<div class="post-metadata">

**Author:** ![dyl](https://avatars.discourse-cdn.com/v4/letter/d/5fc32e/32.png) [@dyl](https://discuss.elastic.co/u/dyl)\
**Post date:** [May 2, 2018, 7:48am UTC](https://discuss.elastic.co/t/how-to-draw-pie-chart-with-sum-of-two-columns/127060/10 "2018-05-02T07:48:38Z")

</div>

@Bargs

Thank you ! It solves my problem

---

<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:** [May 30, 2018, 7:48am UTC](https://discuss.elastic.co/t/how-to-draw-pie-chart-with-sum-of-two-columns/127060/11 "2018-05-30T07:48:47Z")

</div>

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