如何在 VegaLite 中设置动态最大域

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

我有一个流数据的 vega-lite 图,我希望 x 轴的

domainMax
始终比数据范围高一个值。

我使用

ExprRef
来指定我想要的内容

"encoding": {
    "x": {
      "field": "time",
      "type": "quantitative",
      "scale": {
        "domainMax": {
          "expr": "extent(datum.time)[1] + 1"
        }
      },
   }
}

但是我在 Vega 编辑器日志中收到以下错误

[Error] datum is not defined

完整规范可在此处找到:在 Vega 编辑器中打开

如有任何帮助,我们将不胜感激

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

我认为你不能在那里参考数据。试试这个:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "width": 200,
  "height": 200,
  "description": "Evolution of sigma_x and sigma_y",
  "data": {
    "name": "sx_sy",
    "values": [
      {
        "time": 74.54999999999791,
        "sigma_x,sigma_y": -0.6484937856688245,
        "type": "σx"
      },
      {
        "time": 74.54999999999791,
        "sigma_x,sigma_y": 0.7451802282585529,
        "type": "σy"
      },
      {
        "time": 74.5999999999979,
        "sigma_x,sigma_y": -0.6857527970817522,
        "type": "σx"
      },
      {
        "time": 74.5999999999979,
        "sigma_x,sigma_y": 0.7108925884044653,
        "type": "σy"
      }
    ]
  },
  "transform": [
    {"joinaggregate": [{"op": "max", "field": "time", "as": "max"}]}
  ],
  "params": [{"name": "max", "expr": "data('data_0')[0]['max']"}],
  "mark": {"type": "line", "clip": true},
  "encoding": {
    "x": {
      "field": "time",
      "type": "quantitative",
      "scale": {"domainMax": {"expr": "max+0.1"}},
      "axis": {
        "labelFontSize": 20,
        "titleFontSize": 25,
        "title": "time (seconds)"
      }
    },
    "y": {
      "field": "sigma_x,sigma_y",
      "type": "quantitative",
      "scale": {"domain": [-1, 1]},
      "axis": {"labelFontSize": 20, "titleFontSize": 25, "title": "σx, σy"}
    },
    "color": {
      "field": "type",
      "type": "nominal",
      "legend": {"labelFontSize": 20, "title": ""}
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.