# Kibana multi-line chart with legend help

**URL:** <https://discuss.elastic.co/t/kibana-multi-line-chart-with-legend-help/299769>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [March 15, 2022, 6:26pm UTC](https://discuss.elastic.co/t/kibana-multi-line-chart-with-legend-help/299769 "2022-03-15T18:26:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tingda\_Du](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tingda_du/32/96433_2.png) [@Tingda\_Du](https://discuss.elastic.co/u/Tingda_Du)\
**Post date:** [March 15, 2022, 6:26pm UTC](https://discuss.elastic.co/t/kibana-multi-line-chart-with-legend-help/299769/1 "2022-03-15T18:26:49Z")

</div>

I would like to draw a multi-line chart with legend from a query with format  
like the following:

```auto
 "aggregations": {
    "time_buckets": {
      "buckets": [
        {
          "key_as_string": "2022-02-22T00:00:00.000Z",
          "key": 1645488000000,
          "doc_count": 18478,
          "count": {
            "doc_count": 25570,
            "categories_count": {
              "doc_count_error_upper_bound": 0,
              "sum_other_doc_count": 0,
              "buckets": [
                {
                  "key": 3,
                  "doc_count": 4218
                },
                {
                  "key": 1,
                  "doc_count": 3398
                },
                {
                  "key": 5,
                  "doc_count": 2218
                },
                {
                  "key": 0,
                  "doc_count": 38
                }
              ]
            }
          }
        },

```

I would like to draw the chart with x-axis to be time and y axis to be line chart of doc\_count based on each key value of inner buckets with the legend to be the value of the key. Any help will be appreciated.  
Note that the aggregated value might be missing for some buckets so need to handle when the key is missing in one time buckets (set the key count to 0). But you may assume only the key can be {0,1,2,3,4,5,6,7}

---

<div class="post-metadata">

**Author:** ![drewdaemon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drewdaemon/32/97779_2.png) [@drewdaemon](https://discuss.elastic.co/u/drewdaemon)\
**Post date:** [March 15, 2022, 9:23pm UTC](https://discuss.elastic.co/t/kibana-multi-line-chart-with-legend-help/299769/2 "2022-03-15T21:23:57Z")

</div>

Hi Tingda!

I used your Elasticsearch response in an example in the Vega editor [here](https://vega.github.io/editor/#/url/vega-lite/N4IgJAzgxgFgpgWwIYgFwhgF0wBwqgegIDc4BzJAOjIEtMYBXAI0poHsDp5kTykBaADZ04JAKyUAVhDYA7EABoQmOoLhoQAUQAeSBDjUACALINBKoTVlxDAYRhIATpkUgAJkkwpUoYkkEMcBBooEhkZI58KnLBPso0CHAA+kwMUADWcJixoKkZWbEA2qCZAJ5JSBBJEJiOVmQaAEwADI2N-K38bQAqzc2ofQPNlH3NAFquZWgAjABsACxi8wAcy6OjSm5sUElQbAyyLqjTy-MA7MtKewdHoFs714dojWJiZ81XnuRsdUG7+084vd-jcknBHI4fkkGDgcOCUgC3GgPiAIAwEEk2PR4cDHkcUXlMtk0MUQFNUABmTbbEGA+aNE4AXwUJTgpRm1IeAKOFIpAE5lszWezUGJObSjm0mSyyWzkeK8WgKYKALqM9UysoVKo1OqyBroFptDrtRoU3r9QZ9EZ9CZKclzRZvebzdYo3HcmanC5XT1AmmK1AvN4oqBfMg-Gh-QN3APcsEQqEwuGOBEHJEDJRojFY+Cpj03eUgQkFEnCpUKv306Xl46VwuU-mCzVy0X1wFS5u191xhvKxlq9WD5kgABmP2QtxAOEhKcwIpAYQiUXYsgglBUiRSaSJ65LxI1ykcSDX48cCDLY8EnkwcHkqEKIDxlDDt4jvyqz-3wRVSkqJOLHdSzVX8QGQRx0g0YRrFcO89jceoQhAbQkNHKNBAzWV2SUec4Q0W99B+fxXCQbQaByeJMDUNBR38CA4EPEVQDQuAMI0b9KALJ4cNKPD0AARwYE8VC8FRSBIsiKJE6j0AAEW2dE70wQxFUPPZBB+VD0Mwjiph4viQFkNgECsYj1UZIA).

What you're describing also sounds very similar to the visualization we walk through in the [Kibana Vega tutorial](https://www.elastic.co/guide/en/kibana/current/vega.html). I think this may help as well, especially if you are wondering how to put your Elasticsearch query in the Vega config in Kibana.

Let me know if these help!

---

<div class="post-metadata">

**Author:** ![Tingda\_Du](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tingda_du/32/96433_2.png) [@Tingda\_Du](https://discuss.elastic.co/u/Tingda_Du)\
**Post date:** [March 15, 2022, 9:38pm UTC](https://discuss.elastic.co/t/kibana-multi-line-chart-with-legend-help/299769/4 "2022-03-15T21:38:11Z")

</div>

Thank you so much for the help! Really appreciated.

---

<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:** [April 12, 2022, 9:38pm UTC](https://discuss.elastic.co/t/kibana-multi-line-chart-with-legend-help/299769/5 "2022-04-12T21:38:54Z")

</div>

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