繁体   English   中英

Vega-Lite - 如何在每个 nar 中使用带有标签的 plot 堆叠条?

[英]Vega-Lite - How to plot stacked bar with labels in each nar?

给定一个堆积条 plot,如何添加带有每个条的值的标签?

下面是我正在尝试做的一个例子: 堆积条示例

您可以通过将条形标记和文本标记分层来做到这一点。 例如( 在编辑器中打开):

{
  "data": {"url": "data/barley.json"},
  "width": 400,
  "encoding": {
    "x": {
      "type": "quantitative",
      "aggregate": "sum",
      "field": "yield",
      "stack": "zero"
    },
    "y": {"type": "nominal", "field": "variety"}
  },
  "layer": [
    {
      "mark": "bar",
      "encoding": {"color": {"type": "nominal", "field": "site"}}
    },
    {
      "mark": {"type": "text", "color": "white", "dx": -15, "dy": 3},
      "encoding": {
        "detail": {"type": "nominal", "field": "site"},
        "text": {
          "type": "quantitative",
          "aggregate": "sum",
          "field": "yield",
          "format": ".1f"
        }
      }
    }
  ]
}

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM