简体   繁体   English

Vega-lite:轴中标签的换行或自动换行

[英]Vega-lite: Line break or word wrap for labels in axis

I was trying to wrap the labels of x-axis on next line as the labels length is quite long.我试图将 x 轴的标签包装在下一行,因为标签长度很长。 So is there any way to achieve it.那么有什么方法可以实现它。 I tried using calculate and labelExpr by breaking the label string and then concatenating them using '\\n' but that doesn't seem to work.我尝试通过破坏标签字符串然后使用 '\\n' 连接它们来使用calculatelabelExpr但这似乎不起作用。

Is there any other config which will help me achieve this use case or any workaround ?是否有任何其他配置可以帮助我实现此用例或任何解决方法? You can refer the config here - vega-lite .您可以在此处参考配置 - vega-lite

Newline characters in strings cannot be used to display line breaks.字符串中的换行符不能用于显示换行符。 You can generate a line break in most Vega-Lite strings by instead passing a list of strings.您可以通过传递字符串列表来在大多数 Vega-Lite 字符串中生成换行符。

For your chart, you can generate line breaks using the split() operation in a calculate transform:对于您的图表,您可以在计算转换中使用split()操作生成换行符:

  "transform": [{"calculate": "split(datum.address, ' ')", "as": "address"}],

The result looks like this ( view in editor ):结果如下所示( 在编辑器中查看):

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM