为什么使用垂直方向为我的分层线图不做任何事情?

发布于 2025-02-10 09:14:51 字数 852 浏览 2 评论 0原文

如果我将水平更改为垂直在这里,轴不切换:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "layer": [{
      "data": {"values": [
        {"x": 0.5, "y": 0},
        {"x": 1, "y": 1},
        {"x": 2, "y": 2}]},
      "mark": {"type": "line", "orient": "horizontal"},
      "encoding": {
        "x": {"field": "x", "type": "quantitative"},
        "y": {"field": "y", "type": "quantitative"},
        "color": {"datum": "a"}}
    }, {
      "data": {"values": [
        {"x": 1, "y": 0},
        {"x": 2, "y": 1},
        {"x": 2.5, "y": 2}]},
      "mark": {"type": "line", "orient": "horizontal"},
      "encoding": {
        "x": {"field": "x", "type": "quantitative"},
        "y": {"field": "y", "type": "quantitative"},
        "color": {"datum": "b"}}
    }
  ]
}

为什么?如何使X轴和Y轴切换位置?

If I change horizontal to vertical here, the axes don't switch:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "layer": [{
      "data": {"values": [
        {"x": 0.5, "y": 0},
        {"x": 1, "y": 1},
        {"x": 2, "y": 2}]},
      "mark": {"type": "line", "orient": "horizontal"},
      "encoding": {
        "x": {"field": "x", "type": "quantitative"},
        "y": {"field": "y", "type": "quantitative"},
        "color": {"datum": "a"}}
    }, {
      "data": {"values": [
        {"x": 1, "y": 0},
        {"x": 2, "y": 1},
        {"x": 2.5, "y": 2}]},
      "mark": {"type": "line", "orient": "horizontal"},
      "encoding": {
        "x": {"field": "x", "type": "quantitative"},
        "y": {"field": "y", "type": "quantitative"},
        "color": {"datum": "b"}}
    }
  ]
}

Why is that? How to get the x-axis and y-axis to switch places?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泼猴你往哪里跑 2025-02-17 09:14:51

还必须切换“编码”的“ x”和“ y”属性:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "layer": [{
      "data": {"values": [
        {"x": 0.5, "y": 0},
        {"x": 1, "y": 1},
        {"x": 2, "y": 2}]},
      "mark": {"type": "line", "orient": "vertical"},
      "encoding": {
        "x": {"field": "y", "type": "quantitative"},
        "y": {"field": "x", "type": "quantitative"},
        "color": {"datum": "a"}}
    }, {
      "data": {"values": [
        {"x": 1, "y": 0},
        {"x": 2, "y": 1},
        {"x": 2.5, "y": 2}]},
      "mark": {"type": "line", "orient": "vertical"},
      "encoding": {
        "x": {"field": "y", "type": "quantitative"},
        "y": {"field": "x", "type": "quantitative"},
        "color": {"datum": "b"}}
    }
  ]
}

It's also necessary to switch the "x" and "y" properties of "encoding":

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "layer": [{
      "data": {"values": [
        {"x": 0.5, "y": 0},
        {"x": 1, "y": 1},
        {"x": 2, "y": 2}]},
      "mark": {"type": "line", "orient": "vertical"},
      "encoding": {
        "x": {"field": "y", "type": "quantitative"},
        "y": {"field": "x", "type": "quantitative"},
        "color": {"datum": "a"}}
    }, {
      "data": {"values": [
        {"x": 1, "y": 0},
        {"x": 2, "y": 1},
        {"x": 2.5, "y": 2}]},
      "mark": {"type": "line", "orient": "vertical"},
      "encoding": {
        "x": {"field": "y", "type": "quantitative"},
        "y": {"field": "x", "type": "quantitative"},
        "color": {"datum": "b"}}
    }
  ]
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文