gpt4 book ai didi

elasticsearch - 使用Vega-lite在基巴纳分组的条形图

转载 作者:行者123 更新时间:2023-12-03 02:34:36 25 4
gpt4 key购买 nike

通过查看https://vega.github.io/editor/#/examples/vega-lite/bar_grouped,它显示了根据数据表创建分组条形图的示例。

就我而言,由于我是从Elasticsearch获取数据的,因此它不是表格形式的。

我想不出一种方法来为存储桶上的每个总和指标创建两个条形图。

"buckets" : [
{
"key_as_string" : "03/Dec/2019:00:00:00 +0900",
"key" : 1575298800000,
"doc_count" : 11187,
"deploy_agg" : {
"buckets" : {
"deploy_count" : {
"doc_count" : 43
}
}
},
"start_agg" : {
"buckets" : {
"start_count" : {
"doc_count" : 171
}
}
},
"sum_start_agg" : {
"value" : 171.0
},
"sum_deploy_agg" : {
"value" : 43.0
}
},..

我想创建两个小节,一个代表sum_start_agg的值,另一个代表sum_deploy_agg的值。

这就是我的一张条形图。
  "encoding": {
"x": {
"field": "key",
"type": "temporal",
"axis": {"title": "DATE"}
},
"y": {
"field": "deploy_agg.buckets.deploy_count.doc_count",
"type": "quantitative",
"axis": {"title": "deploy_count"}
}
"color": {"value": "green"}
"tooltip": [
{
"field": "deploy_agg.buckets.deploy_count.doc_count",
"type": "quantitative",
"title":"value"
}
]
}

最佳答案

您可以使用Fold Transform折叠两列,以便可以在编码中引用它们。它可能看起来像这样:

{
"data": {
"values": [
{
"key_as_string": "03/Dec/2019:00:00:00 +0900",
"key": 1575298800000,
"doc_count": 11187,
"deploy_agg": {"buckets": {"deploy_count": {"doc_count": 43}}},
"start_agg": {"buckets": {"start_count": {"doc_count": 171}}},
"sum_start_agg": {"value": 171},
"sum_deploy_agg": {"value": 43}
}
]
},
"transform": [
{
"fold": ["sum_start_agg.value", "sum_deploy_agg.value"],
"as": ["entry", "value"]
}
],
"mark": "bar",
"encoding": {
"x": {"field": "entry", "type": "nominal", "axis": null},
"y": {"field": "value", "type": "quantitative"},
"column": {"field": "key", "type": "temporal"},
"color": {"field": "entry", "type": "nominal"}
}
}

enter image description here

关于elasticsearch - 使用Vega-lite在基巴纳分组的条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59149963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com