【问题标题】:Calculation in vega在 vega 中计算
【发布时间】:2017-11-14 12:48:51
【问题描述】:

我在 Kibana 中使用 vega。

我从“数据”部分的两个不同索引中选择两个值。但现在我需要总结这些值并将其可视化在“标记”部分。有谁知道,我该怎么做?现在在“标记”部分,我只使用第一个“数据”中的一个值。

我的代码如下:

    {
  "$schema": "https://vega.github.io/schema/vega/v3.0.json",
  "title": {
    "text": "Lead time, hr.",
    "orient": "bottom"
  },
  "data": [
    {
      "name": "source_1",
      "url": {
        "index": "metrics-bitbucket-*",
        "%context_query%": "@timestamp",
        "body": {
          "size": 0,
          "aggs": {
            "etb": {
              "avg": {
                "field": "elapsed_time",
                "script": {"source": "_value/3600*10"}
              }
            }
          }
        }
      },
      "format": {"type": "json", "property": "aggregations.etb"}
    },
    {
      "name": "source_2",
      "url": {
        "index": "metrics-jenkins-*",
        "%context_query%": "@timestamp",
        "body": {
          "size": 0,
          "aggs": {
            "etj": {
              "avg": {
                "field": "elapsed_time",
                "script": {"source": "_value/3600*10"}
              }
            }
          }
        }
      },
      "format": {"type": "json", "property": "aggregations.etj"}
    }
  ],
  "marks": {
    "type": "text",
    "from": {"data": "source_1"},
    "encode": {
      "update": {
        "text": {"signal": "round(datum.value)/10"},
        "fontSize": {"value": 60},
        "fontStyle": {"value": "bold"},
        "x": {"signal": "width/2-50"},
        "y": {"signal": "height/2"}
      }
    }
  }
}

【问题讨论】:

    标签: vega


    【解决方案1】:

    您实际上有两个数据对象列表:source1: [{}, {}, ...]source2: [{}, {}, {}, ...]。绘制项目时,您只需指定一个数据源。该数据源可以是前两个的串联,例如您创建source3 并将其source 参数设置为["source1", "source2"],其中包括两者的所有元素,但我怀疑这不是您想要的。相反,您需要使用 lookup transform 合并数据 - 迭代一个数据源中的项目,并从另一个数据源中提取相应的值。然后,添加一个formula transform 来对这些值求和。标记将使用公式的结果进行绘图。

    【讨论】:

      猜你喜欢
      • 2020-06-17
      • 2020-09-27
      • 2015-06-19
      • 2020-04-22
      • 1970-01-01
      • 2020-03-19
      • 1970-01-01
      • 2019-06-02
      • 2019-05-07
      相关资源
      最近更新 更多