【问题标题】:How can I put a line break in a Vega-lite axis title?如何在 Vega-lite 轴标题中放置换行符?
【发布时间】:2019-11-28 16:01:00
【问题描述】:

我是 Vega-lite 的新手,我想弄清楚轴标题中是否可以换行。我有一个长轴标题,例如:

“长轴标题太长,图下放不下”

我试过了:

“长轴标题太长\n 无法放入图表下方”和
"长轴标题太\
长到适合图表下方”

“\n”似乎没有做任何事情。 "\[enter]" 只是在行中增加了额外的空间。

我的 x 和 y 编码如下所示:

encoding: {
      x: {field: 'a',
          type: 'ordinal',
          sort: {"encoding": "x"},  
          axis: {"title": "Knowledge of the elder\
          categories would melt\
          your psyche",
          "titleFontSize": 30,
          }
          },
      y: {field: 'b', 
          type: 'quantitative',
          axis: {"title": "Your puny mortal mind\ncannot comprehend the units\nof the multiverse!",
          "titleFontSize": 14,
          }
          }
    }

我没有收到错误消息,但我也没有收到换行符。我要么没有变化(来自 \n),要么得到奇怪的间距(来自 [enter])。

谢谢!

【问题讨论】:

    标签: vega-lite


    【解决方案1】:

    在 Vega-Lite 4.0 或更新版本中,可以通过传递字符串数组在标题中指定多行文本。例如:

    {"data": {
        "values": [
          {"a": "A", "b": 28},
          {"a": "B", "b": 55},
          {"a": "C", "b": 43},
          {"a": "D", "b": 91},
          {"a": "E", "b": 81},
          {"a": "F", "b": 53},
          {"a": "G", "b": 19},
          {"a": "H", "b": 87},
          {"a": "I", "b": 52}
        ]
      },
      "mark": "bar",
      "encoding": {
        "x": {
          "field": "a",
          "type": "ordinal",
          "title": ["First line of title", "second line of title"]
        },
        "y": {"field": "b", "type": "quantitative"}
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-08-03
      • 2019-06-02
      • 2020-03-27
      • 1970-01-01
      • 2022-11-03
      • 2022-06-10
      • 2018-01-18
      • 1970-01-01
      • 2020-07-05
      相关资源
      最近更新 更多