# Create weekday barchart from timestamp

**URL:** <https://discuss.elastic.co/t/create-weekday-barchart-from-timestamp/139053>\
**Category:** Kibana\
**Created:** [July 8, 2018, 11:48am UTC](https://discuss.elastic.co/t/create-weekday-barchart-from-timestamp/139053 "2018-07-08T11:48:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![OlivierV](https://avatars.discourse-cdn.com/v4/letter/o/919ad9/32.png) [@OlivierV](https://discuss.elastic.co/u/OlivierV)\
**Post date:** [July 8, 2018, 11:48am UTC](https://discuss.elastic.co/t/create-weekday-barchart-from-timestamp/139053/1 "2018-07-08T11:48:04Z")

</div>

Hi,

I am trying to create a bar chart where I have both the average documents count per day of the week (eg Monday to Sunday) over the entire period and the documents count over the current week.  
So far I have only managed to query the total documents count per day of the week (see query below) but I don't know how to create the visualization.

```
POST /myindex/_search?size=0
{
  "query":{
    "match_all": {}
  },
    "aggs": {
        "dayOfWeek": {
            "terms": {
                "script": {
                    "lang": "painless",
                    "source": "doc['date'].value.dayOfWeek"
                }
            }
        }
    }
}

```

The result I would like to obtain is as follows:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/4/e4d160a54a8b97f6dfb1af72ce9b61d7dbb986d9.png)

Thanks for you help

---

<div class="post-metadata">

**Author:** ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)\
**Post date:** [July 9, 2018, 4:52pm UTC](https://discuss.elastic.co/t/create-weekday-barchart-from-timestamp/139053/2 "2018-07-09T16:52:24Z")

</div>

Hey @OlivierV, you'll want to start by creating a Kibana [scripted field](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html) for the `dayOfWeek`, and then you can create a Vertical Bar Chart with the following configuration:

 ![26%20PM](https://us1.discourse-cdn.com/elastic/original/3X/b/e/be3e391e66710a7aedcfbc2fc2689766729dd91b.png) ![36%20PM](https://us1.discourse-cdn.com/elastic/original/3X/4/d/4d3edcf4cfdca31c5ae7ea313665e3340d562b55.png)

Make sure that you include the "JSON Input" sections, to get gaps to be reflected right in the averages.

---

<div class="post-metadata">

**Author:** ![OlivierV](https://avatars.discourse-cdn.com/v4/letter/o/919ad9/32.png) [@OlivierV](https://discuss.elastic.co/u/OlivierV)\
**Post date:** [July 10, 2018, 9:28am UTC](https://discuss.elastic.co/t/create-weekday-barchart-from-timestamp/139053/3 "2018-07-10T09:28:01Z")

</div>

Thanks it worked!

I just have one more issue which is UI related: how can I map the day\_of\_week values (eg 1 to 7) to string values Monday to Sunday on the chart?

---

<div class="post-metadata">

**Author:** ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)\
**Post date:** [July 10, 2018, 11:38am UTC](https://discuss.elastic.co/t/create-weekday-barchart-from-timestamp/139053/4 "2018-07-10T11:38:38Z")

</div>

Hey @OlivierV, I'd recommend changing your scripted field to return the string of Monday to Sunday. There isn't away via Kibana's Visualize to perform this translation at the moment.

---

<div class="post-metadata">

**Author:** ![OlivierV](https://avatars.discourse-cdn.com/v4/letter/o/919ad9/32.png) [@OlivierV](https://discuss.elastic.co/u/OlivierV)\
**Post date:** [July 10, 2018, 1:05pm UTC](https://discuss.elastic.co/t/create-weekday-barchart-from-timestamp/139053/5 "2018-07-10T13:05:27Z")

</div>

Yeah that's what I've tried but then it messes the way days are ordered like it orders them alphabetically

---

<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:** [August 7, 2018, 1:05pm UTC](https://discuss.elastic.co/t/create-weekday-barchart-from-timestamp/139053/6 "2018-08-07T13:05:30Z")

</div>

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