【问题标题】:Grouped bar-chart in Kibana using Vega-lite使用 Vega-lite 在 Kibana 中分组条形图
【发布时间】:2020-03-27 17:13:39
【问题描述】:

通过查看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"
        }
      ]
  }

【问题讨论】:

    标签: elasticsearch kibana vega-lite


    【解决方案1】:

    您可以使用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"}
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-03
      • 2021-12-19
      • 2021-08-22
      • 1970-01-01
      • 1970-01-01
      • 2021-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多