我很难弄清楚如何使用聚合/嵌套在 Vega 中构建多视图图表。
我相信这与我尝试转换数据以在 Vega 多视图图表中使用的方式有关。谁能帮我理解这一点?
我知道展平转换正在像调试节目一样工作
但我得到的是这个
这就是我想要实现的
这是我构建图表的架构
{
"$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 }
}
}
}
我做了很多事情,但无法理解它有什么问题