elasticsearch - Vega-lite热图将文本添加到变量

标签 elasticsearch heatmap vega vega-lite

"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}
]},

如何将文本添加到变量,例如“AVG:”?
enter image description here

Vega Editor

最佳答案

您可以使用计算转换来创建特殊格式的文本以在文本标记中显示。例如(vega editor):

{
  "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}
    ]
  },
  "transform": [
    {
      "aggregate": [{"op": "mean", "field": "z", "as": "z"}],
      "groupby": ["x", "y"]
    },
    {"calculate": "'avg: ' + datum.z", "as": "z"}
  ],
  "mark": "text",
  "encoding": {
    "x": {"field": "x", "type": "ordinal"},
    "y": {"field": "y", "type": "ordinal"},
    "text": {"field": "z", "type": "nominal"}
  },
  "width": 300,
  "height": 100
}

enter image description here

关于elasticsearch - Vega-lite热图将文本添加到变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59731790/

相关文章:

python - 不使用 Matplotlib Python 在后台获取热图

r - 如何使用scale_fill_gradient指定 "low"和 "high"并在两端获得两个音阶

vega-lite - 日期解析以及何时在 Vega Lite 中使用 utc/Time Units?

elasticsearch - 一种类型不存在的Elasticsearch记录

elasticsearch - 如何在elasticsearch中控制和轮换存储数据

python - Elasticsearch - Python 客户端 - 如何匹配多个字段?

ElasticSearch - 聚合+范围+术语查询

java - 创建鼠标移动可视化效果最丰富的方法是什么?

powerbi - Vega-lite 项目 : Risk matrix

r - 让 ggvis::export_png() 工作