用Vega绘制堆积图

时间:2019-04-05 17:11:10

标签: elasticsearch kibana vega

我无法将这些数据绘制成堆积图。在聚合的“持续时间”字段上,我还需要执行其他计算。首先,我需要在x轴上按Task.ID分组-然后将Duration放在Y轴上。由Current.BotState分隔。

我需要绘制的计算结果是TaskID的TotalDuration-TargetTime(TBD)-TotalBlockedTime / TargetTime

  "$schema": "https://vega.github.io/schema/vega/v3.3.1.json",
  "padding": 5,

  "data": [
    {
      "name": "table",
      "values": [
        {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "7FKj6GkBcbTp5jzWhwT-",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "8195"
          },
          "Duration" : 11.954,
          "Current" : {
            "BotState" : "Working"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "9FKj6GkBcbTp5jzWhwT-",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "8195"
          },
          "Duration" : 11.703,
          "Current" : {
            "BotState" : "Blocked"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "-FKj6GkBcbTp5jzWhwT-",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "0"
          },
          "Duration" : 7.469,
          "Current" : {
            "BotState" : "Unscheduled"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "CVKj6GkBcbTp5jzWohqo",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "1673"
          },
          "Duration" : 4.172,
          "Current" : {
            "BotState" : "Blocked"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "ClKj6GkBcbTp5jzWohqo",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "1673"
          },
          "Duration" : 0.516,
          "Current" : {
            "BotState" : "Starved"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "D1Kj6GkBcbTp5jzWohqo",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "2551"
          },
          "Duration" : 28.846,
          "Current" : {
            "BotState" : "Working"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "GVKj6GkBcbTp5jzWohqo",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "2287"
          },
          "Duration" : 10.772,
          "Current" : {
            "BotState" : "Working"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "0lKj6GkBcbTp5jzWmhN6",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "8721"
          },
          "Duration" : 11.689,
          "Current" : {
            "BotState" : "Working"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "1VKj6GkBcbTp5jzWmhN6",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "8721"
          },
          "Duration" : 1.11,
          "Current" : {
            "BotState" : "Blocked"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "H1Kj6GkBcbTp5jzWriXC",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "8584"
          },
          "Duration" : 9.801,
          "Current" : {
            "BotState" : "Working"
            }
        }
      }
      ],
      "transform": [
        {
          "type": "stack",
          "groupby": ["_source.Task.Id"],
          "sort": {"field": "_source.Current.BotState"},
          "field": "_source.Duration"
        }
      ]
    }
  ],

  "scales": [
    {
      "name": "x",
      "type": "band",
      "range": "width",
      "domain": {"data": "table", "field": "_source.Task.Id"}
    },
    {
      "name": "y",
      "type": "linear",
      "range": "height",
      "nice": true, "zero": true,
      "domain": {"data": "table", "field": "_source.Duration"}
    },
    {
      "name": "color",
      "type": "ordinal",
      "range": "category",
      "domain": {"data": "table", "field": "_source.Current.BotState"}
    }
  ],

  "axes": [
    {"orient": "bottom", "scale": "x", "zindex": 1},
    {"orient": "left", "scale": "y", "zindex": 1}
  ],

  "marks": [
    {
      "type": "rect",
      "from": {"data": "table"},
      "encode": {
        "enter": {
          "x": {"scale": "x", "field": "_source.Task.Id"},
          "width": {"scale": "x", "band": 1, "offset": -1},
          "y": {"scale": "y", "field": "_source.Duration0"},
          "y2": {"scale": "y", "field": "_source.Duration1"},
          "fill": {"scale": "color", "field": "_source.Current.BotState"}
        },
        "update": {
          "fillOpacity": {"value": 1}
        },
        "hover": {
          "fillOpacity": {"value": 0.5}
        }
      }
    }
  ]
}

0 个答案:

没有答案