I am having a hard time figuring out how to build a multiview chart in Vega using aggregated/nested.
I believe it is related to the way I am trying to transform my data to use in Vega multi view chart. Can anyone give me a hand to understand this?
I know flatten transformation is working as debug shows
But what I get is this
This is what I would like to achieve
This is my schema to build the chart
{
"$schema": "https://vega.github.io/schema/vega/v3.json",
"width": 400,
"height": 200,
"padding": 5,
"data": [
{
"name": "source",
"values": {
"aggregations": {
"order_labels": {
"buckets": [
{
"key": "USD/CAD",
"doc_count": 1,
"orders": {
"doc_count": 40,
"orders_id": {
"buckets": [
{
"key": 5241,
"doc_count": 1,
"orders_price": {"value": 0.01991}
},
{
"key": 5242,
"doc_count": 1,
"orders_price": {"value": 0.02021}
}
]
}
}
},
{
"key": "CAD/COD",
"doc_count": 1,
"orders": {
"doc_count": 40,
"orders_id": {
"buckets": [
{
"key": 5041,
"doc_count": 1,
"orders_price": {"value": 0.00002953}
},
{
"key": 5042,
"doc_count": 1,
"orders_price": {"value": 0.00002971}
}
]
}
}
}
]
}
}
},
"format": {"property": "aggregations.order_labels.buckets"},
"transform": [
{
"type": "flatten",
"fields": ["orders.orders_id.buckets"],
"as": ["orders"]
}
]
}
],
"mark": "bar",
"encoding": {
"row": {
"field": "orders.key",
"type": "ordinal"
},
"x": {
"aggregate": "sum",
"field": "orders.orders_price.value",
"type": "quantitative",
"scale": { "zero": false }
},
"y": {
"field": "key",
"type": "ordinal",
"scale": { "rangeStep": 12 }
}
}
}
I did many things but can`t understand what is wrong with it