# Chart-Title from data values

**URL:** <https://discuss.elastic.co/t/chart-title-from-data-values/327998>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [March 18, 2023, 5:02pm UTC](https://discuss.elastic.co/t/chart-title-from-data-values/327998 "2023-03-18T17:02:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![joerg55](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@joerg55](https://discuss.elastic.co/u/joerg55)\
**Post date:** [March 18, 2023, 5:02pm UTC](https://discuss.elastic.co/t/chart-title-from-data-values/327998/1 "2023-03-18T17:02:31Z")

</div>

Hi community,

I know this is not necessarily a question for this forum, but I hope someone might be able to help. I want to take the title of my chart directly from the data which are base of the chart. For example the title of this chart should be 'charttitle':

```auto
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{"quater":"1", "sales":"100", "title":"charttitle"},
{"quater":"2", "sales":"200", "title":"charttitle"},
{"quater":"3", "sales":"300", "title":"charttitle"},
{"quater":"4", "sales":"400", "title":"charttitle"}
]
},

"mark": "bar",
"encoding": {
"x": {"field": "quater", "type":"ordinal"},
"y": {"field": "sales", "type": "quantitative"},
},
"title": ???
}

```

How can I achieve this?

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [March 20, 2023, 9:35am UTC](https://discuss.elastic.co/t/chart-title-from-data-values/327998/4 "2023-03-20T09:35:41Z")

</div>

Hi @joerg55

I think the best option here is to define a transform of the data and reduce the data into a single value to use as title.

---

<div class="post-metadata">

**Author:** ![joerg55](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@joerg55](https://discuss.elastic.co/u/joerg55)\
**Post date:** [March 20, 2023, 10:15am UTC](https://discuss.elastic.co/t/chart-title-from-data-values/327998/5 "2023-03-20T10:15:03Z")

</div>

Hi Marco,

that is exactly what I try to do. In pseudo code it could look like this:

- "title": (select title from data limit 1); or in standard sql

- "title": (select top 1 title from data)

but how can i achieve that in vega?

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [March 20, 2023, 12:09pm UTC](https://discuss.elastic.co/t/chart-title-from-data-values/327998/6 "2023-03-20T12:09:20Z")

</div>

In Vega that is a bit tricky, as it requires to add alongside the query data, also another dataset derived from it with the usage of a `transform`.  
The `transform` object can apply different types of aggregations in Vega, probably a combination of a `window` + `filter` would be a good starting point: [Transforms | Vega](https://vega.github.io/vega/docs/transforms/)

---

<div class="post-metadata">

**Author:** ![joerg55](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@joerg55](https://discuss.elastic.co/u/joerg55)\
**Post date:** [March 20, 2023, 12:32pm UTC](https://discuss.elastic.co/t/chart-title-from-data-values/327998/7 "2023-03-20T12:32:37Z")

</div>

@Marco,

thank you very much for your help. I already took a look to the transform.window option and the possibility to isolate a single value by an appropriate filter (e. g. 'rank \<= 1'). My main problem is to assign this single value (which is an object in vega?) to the title of the chart

---

<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 17, 2023, 12:33pm UTC](https://discuss.elastic.co/t/chart-title-from-data-values/327998/8 "2023-04-17T12:33:07Z")

</div>

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