# Use Vega Visualization with Dynamic Data (Index)

**URL:** <https://discuss.elastic.co/t/use-vega-visualization-with-dynamic-data-index/172942>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [March 19, 2019, 10:27am UTC](https://discuss.elastic.co/t/use-vega-visualization-with-dynamic-data-index/172942 "2019-03-19T10:27:38Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![suhasgupta1](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@suhasgupta1](https://discuss.elastic.co/u/suhasgupta1)\
**Post date:** [March 20, 2019, 9:54am UTC](https://discuss.elastic.co/t/use-vega-visualization-with-dynamic-data-index/172942/2 "2019-03-20T09:54:20Z")

</div>

Hi All,

I am able to find the answer and posting it here.  
{  
"$schema": "[https://vega.github.io/schema/vega-lite/v2.3.1.json](https://vega.github.io/schema/vega-lite/v2.3.1.json)",  
"autosize":  
{  
"type": "pad",  
"resize": false  
},  
"data":  
{  
"url": {  
"%context%": true,  
"index": "vizcheck"  
"body":  
{  
"aggs" : {  
"eqpt\_buckets": {  
"composite" : {  
"size": 5000,  
"sources" :  
[  
{  
"EPID":  
{"terms" :  
{  
"field": "EPID"  
}  
}  
},  
{  
"DATE":  
{"terms" :  
{"field": "DATE"  
}  
}  
},  
{  
"CC\_E":  
{"terms" :  
{"field": "CC\_E"  
}  
}  
},  
{  
"NoObj":  
{  
"terms":  
{"field": "NoObj"  
}  
}  
}  
]  
}  
}  
}  
}  
}  
"format": {property: "aggregations.eqpt\_buckets.buckets"}

```
},
  "transform": 
    [
      {"calculate": "datum.key.EPID", 
        "as": "EPID"
      },
      {"calculate": "datum.key.DATE", 
        "as": "DATE"},
      {"calculate": "datum.key.CC_E", 
      "as": "CC_E"
      },
      {"calculate": "datum.key.NoObj",
      "as": "NoObj"
      }
    ],
"mark": "bar",
 "config": 
 {
    "size": 
    {
      "height": 200,
      "width": 200
    },
}
"encoding": 
{
  "x": 
    {
        "field": "DATE",
        "type": "temporal",

    },
  "y": 
    {
        "field":"NoObj", 
        "aggregate": "sum",
        "type": "quantitative"
    }
    ,
  "color": 
    {
      "field": "CC_E", 
      "type": "nominal"
    },
  "row":
    {
      "field": "EPID",
      "type": "nominal"
    }
}

```

}

Main problem with earlier code was we need data to be formatted in the way bar graph needs. So first in the data group we are writing query to get the data and then using the same in below part of the code to draw the chart.

Thanks & Regards  
Suhas Gupta

---

_[View the full topic](https://discuss.elastic.co/t/use-vega-visualization-with-dynamic-data-index/172942)._
