Vega Lite:有没有办法在折叠图上有两层

问题描述 投票:0回答:1

我用这个作为我的参考 - 链接到折叠示例

我不仅想要条形图,还想要另一个显示数据标签的图层。 (像这样 - https://vega.github.io/vega-lite/examples/layer_bar_labels.html

感谢您的帮助。

我尝试添加一个带有“栏”和“文本”层的图层组件,但它结合了两个折叠列。

json charts visualization vega-lite
1个回答
0
投票

enter image description here

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      {"country": "USA", "gold": 10, "silver": 20},
      {"country": "Canada", "gold": 7, "silver": 26}
    ]
  },
  "transform": [{"fold": ["gold", "silver"]}],
  "facet": {"column": {"field": "key"}},
  "spec": {
    "layer": [
      {
        "mark": "bar",
        "encoding": {
          "x": {"field": "country", "type": "nominal"},
          "y": {"field": "value", "type": "quantitative"},
          "color": {"field": "country", "type": "nominal"}
        }
      },
      {
        "mark": {"type": "text", "dy": -4},
        "encoding": {
          "text": {"field": "value", "type": "quantitative"},
          "x": {"field": "country", "type": "nominal"},
          "y": {"field": "value", "type": "quantitative"}
        }
      }
    ]
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.