# Visualization based on time aggregation with the Date Fields

**URL:** <https://discuss.elastic.co/t/visualization-based-on-time-aggregation-with-the-date-fields/128395>\
**Category:** Kibana\
**Created:** [April 17, 2018, 3:52pm UTC](https://discuss.elastic.co/t/visualization-based-on-time-aggregation-with-the-date-fields/128395 "2018-04-17T15:52:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandeep\_Sankarankutt](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@Sandeep\_Sankarankutt](https://discuss.elastic.co/u/Sandeep_Sankarankutt)\
**Post date:** [April 17, 2018, 3:52pm UTC](https://discuss.elastic.co/t/visualization-based-on-time-aggregation-with-the-date-fields/128395/1 "2018-04-17T15:52:16Z")

</div>

My JSON structure looks as follows with more than a million records with the same format with different starttime, endtime and setupnames.

{  
"owner": "Robert",  
"starttime": "2017-12-05T13:24:12.000Z",  
"SetupName": "OA1125",  
"endtime": "2017-12-05T18:24:12.000Z",  
},  
{  
"owner": "Robert",  
"starttime": "2017-12-05T18:24:12.000Z",  
"SetupName": "OA1125",  
"endtime": "2017-12-05T23:25:12.000Z",  
}

I am trying to create a bar chart visualization with total hours spent against each SetupName by calculating the difference between EndTime - StartTime and aggregate over all records.

For Example from the above mentioned JSON the total hours of OA1125 is 10 hours ( 5 hours each from each json ), similar for other setupnames.

The bar chart visualization will be like

Yaxis - SetupName  
Xaxis - Hours

OA1125 : ========== 10 hours  
OA1126 : == 2 hours  
OA1127 : ===== 5 hours

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [April 17, 2018, 7:05pm UTC](https://discuss.elastic.co/t/visualization-based-on-time-aggregation-with-the-date-fields/128395/2 "2018-04-17T19:05:54Z")

</div>

You're going to need to use a scripted field here, where the scripted field would calculate its value from starttime - endtime. Then, you can do a bar chart visualization, y-axis is sum of the scripted field, x-axis is a terms on SetupName.

---

<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 15, 2018, 7:05pm UTC](https://discuss.elastic.co/t/visualization-based-on-time-aggregation-with-the-date-fields/128395/3 "2018-05-15T19:05:58Z")

</div>

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