Chart-Title from data values

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':

"$schema": "",
"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?

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.

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?

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


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

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