# Line diagram showing sum of finished orders over time

**URL:** <https://discuss.elastic.co/t/line-diagram-showing-sum-of-finished-orders-over-time/290818>\
**Category:** Kibana\
**Created:** [December 2, 2021, 7:34pm UTC](https://discuss.elastic.co/t/line-diagram-showing-sum-of-finished-orders-over-time/290818 "2021-12-02T19:34:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxl](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@maxl](https://discuss.elastic.co/u/maxl)\
**Post date:** [December 2, 2021, 7:34pm UTC](https://discuss.elastic.co/t/line-diagram-showing-sum-of-finished-orders-over-time/290818/1 "2021-12-02T19:34:54Z")

</div>

Hello to the elastic community!

I have a problem and I can't figure out how I could achieve this.  
Every few minutes some orders get finished.  
And I want to show how many are finished after 5 mins, after 10 mins, and so on.

So the x axis would be the time and y axis would be the sum of finished orders from start time.

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [December 2, 2021, 8:12pm UTC](https://discuss.elastic.co/t/line-diagram-showing-sum-of-finished-orders-over-time/290818/2 "2021-12-02T20:12:02Z")

</div>

Hi, how is your data structured? Do you get a document when order starts and one when order ends, or just a single one for the whole order? what fields would you have in your document?

---

<div class="post-metadata">

**Author:** ![maxl](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@maxl](https://discuss.elastic.co/u/maxl)\
**Post date:** [December 2, 2021, 8:16pm UTC](https://discuss.elastic.co/t/line-diagram-showing-sum-of-finished-orders-over-time/290818/3 "2021-12-02T20:16:22Z")

</div>

Well it's one label and data gets updated.  
For example `label.order_end` is only set when order is finished.  
So I filter for `if label.order_end` exists.

![image](https://us1.discourse-cdn.com/elastic/original/3X/5/8/581d7720c2f08968e95f173d2b16e4179c3ea4a4.png)

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [December 2, 2021, 8:43pm UTC](https://discuss.elastic.co/t/line-diagram-showing-sum-of-finished-orders-over-time/290818/4 "2021-12-02T20:43:15Z")

</div>

Then it should be pretty straightforward:  
You can map: "labels.order\_end - labels.order\_start" on one axis and count on the other. That calculation can be done in multiple ways:

1. Best way: when you update the order\_end field, add/update a duration field.
2. TSVB math aggregation: you can do the difference there, when you have both fields, but you need to make sure first that you do checks for the label.order\_end field existing first.
3. Scripted field: same as before, you need to do the checks and you can create your own duration field.

---

<div class="post-metadata">

**Author:** ![maxl](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@maxl](https://discuss.elastic.co/u/maxl)\
**Post date:** [December 3, 2021, 9:28am UTC](https://discuss.elastic.co/t/line-diagram-showing-sum-of-finished-orders-over-time/290818/5 "2021-12-03T09:28:06Z")

</div>

Thanks for the fast reply!

I was not specific on the x axis. I don't want the duration, I want the time ( @timestamp ).  
So e.g. at 18:00 we have 0 orders finished, at 18:10 we have 10, then 15, and so on.

Here I got something, but I can't choose @timestamp, only the timestamp in us, which is pretty ugly:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/f/2f86e18fc37a75f6426cd61224801c374fdca9f2.png)

---

<div class="post-metadata">

**Author:** ![maxl](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@maxl](https://discuss.elastic.co/u/maxl)\
**Post date:** [December 3, 2021, 10:15am UTC](https://discuss.elastic.co/t/line-diagram-showing-sum-of-finished-orders-over-time/290818/6 "2021-12-03T10:15:13Z")

</div>

So, eventually I got it to work with lens and cumulative sum.  
Somehow I oversaw this.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/a/eadd259986528e316119c9622e9df582ab647e5d.png)

---

<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:** [December 31, 2021, 10:15am UTC](https://discuss.elastic.co/t/line-diagram-showing-sum-of-finished-orders-over-time/290818/7 "2021-12-31T10:15:27Z")

</div>

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