1)有一个X坐标和一个Y坐标。有一个Z值。 Z需要计算AVG。

"data": {
"values": [
  {"x": 0, "y": 0, "z": 0},
  {"x": 1, "y": 0, "z": 1},
  {"x": 2, "y": 0, "z": 5},
  {"x": 2, "y": 0, "z": 10},
  {"x": 4, "y": 0, "z": 16},
  {"x": 0, "y": 1, "z": 1},
  {"x": 1, "y": 1, "z": 2},
  {"x": 2, "y": 1, "z": 5},
  {"x": 3, "y": 1, "z": 10},
  {"x": 5, "y": 1, "z": 26}
]},

如果数据:
"encoding": {
"x": {"field": "x", "type": "ordinal", "title": "X"},
"y": {"field": "y", "type": "ordinal", "title": "Y"} },

那么AVG是正确的:

Vega Editor

elasticsearch - Vega-lite热图 “transform”无法正常工作-LMLPHP

如果我对“groupby”使用“transform”:
"transform": [  {"window": [{"op": "count", "field": "x", "as": "x2"}], "groupby": ["y"]}],
"encoding": {
    "x": {"field": "x2", "type": "ordinal", "title": "X"},
    "y": {"field": "y", "type": "ordinal", "title": "Y"}
 },

那么AVG是不正确的:
Vega Editor

elasticsearch - Vega-lite热图 “transform”无法正常工作-LMLPHP

最佳答案

转换完全按照您的指示进行:

{"window": [{"op": "count", "field": "x", "as": "x2"}], "groupby": ["y"]}

它通过y对数据进行分组。示意图如下所示:
y=0: x: [0,  1,  2,  2,  4]
     z: [0,  1,  5, 10, 16]

y=1: x: [0,  1,  2,  3, 5]
     z: [1,  2,  5, 10, 26]

然后,它做一个滑动窗口,并将计数分配给x2:
y=0: x:  [0,  1,  2,  2,  4]
     z:  [0,  1,  5, 10, 16]
     x2: [1,  2,  3,  4,  5]

y=1: x:  [0,  1,  2,  3,  5]
     z:  [1,  2,  5, 10, 26]
     x2: [1,  2,  3,  4,  5]

如您所见,当创建yx2的图时,现在每个位置都有一个z值,并且该值正确反射(reflect)在上面显示的图表中。

如果您想要不同的行为,则应指定不同的转换。

关于elasticsearch - Vega-lite热图 “transform”无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59728807/

10-16 10:50