在维加计算

时间:2017-11-14 12:48:52

标签: vega

我在Kibana使用vega。

我从“#34;数据"”部分的两个不同索引中选择两个值。但是现在我需要总结这些值并将其显示在"标记"部分中。有人知道,我怎么能这样做?现在在"标记"我只使用第一个"数据"。

中的一个值

我的代码如下:

    {
  "$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"}
      }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

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