vega-lite - 如何在 Vega-lite 轴标题中放置换行符?
问题描述
我是 Vega-lite 的新手,我试图弄清楚轴标题中是否可以换行。我有一个长轴标题,例如:
“长轴标题太长,不适合图表下方”
我试过了:
“长轴标题太\n 太长,不适合图表”和
“长轴标题太\\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 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"}
}
}
推荐阅读
- c++ - 如何将没有“:”的字符串转换为 const uchar *addr?
- vue.js - 使用 Vue JS 切换活动类
- jquery - 如何对具有特定类的所有标签应用验证?
- r - 在不弄乱对齐的情况下更改 geom_dotplot 点的颜色
- sql-server - 触发错误,不显示 Raiserror 消息
- python - 在 BeautifulSoup中获取 HTML 标签的文本
- ios - 上传到 App Store Connect 的应用预览视频的格式问题
- css - 带有定位图层的背景图像上的 CSS 灰度
- ios - iOS如何从透明的.png生成纹理网格?
- c++ - 求给定矩阵中的总循环数