theta 和 theta2 通道编码按场

theta and theta2 chanel encoding by field

我想使用 vega-lite 创建圆弧,在这里你会找到一个工作示例:enter link description here

但这不起作用:enter link description here

区别仅在于我在工作示例中使用了它

"encoding": {
"theta": {"value": {"expr": "datum.thta"}},
"theta2": {"value": {"expr": "datum.thta2"}}  }

这是不起作用的代码:

"encoding": {
"theta": {"field": "thta"}, 
"theta2": {"field": "thta2"}}  }

有人可以解释为什么使用“字段”创建半圆(不需要)而使用“值”创建四分之一圆(需要)吗?

非常感谢

当您通过编码指定值时,比例会根据数据内容自动调整。您可以通过指定比例应为 0 到 2pi (open in editor) 来解决此问题:

{
  "width": 80,
  "height": 80,
  "params": [{"name": "radius", "value": 0}, {"name": "radius2", "value": 50}],
  "data": {
    "values": [{"name": "arc1", "quadrant": "TopRight", "ring": "Hold"}]
  },
  "transform": [
    {
      "calculate": "if(datum.quadrant === 'TopRight'  , PI*0.5 , null)",
      "as": "thta2"
    },
    {"calculate": "if(datum.quadrant === 'TopRight'  , 0 , null)", "as": "thta"}
  ],
  "mark": {
    "type": "arc",
    "radius": {"expr": "radius"},
    "radius2": {"expr": "radius2"}
  },
  "encoding": {
    "theta": {"field": "thta", "scale": {"domain": [0, "2*PI"]}},
    "theta2": {"field": "thta2"}
  }
}