UI要求是这样的,但是出来的legend的text是在同一行
开始想用</ br>,但是未生效,后来改成了\n换行符,就搞定了,formatter字符串模板不支持html解析
legend: {
left: 'right',
width: '60%',
top: 'center',
itemWidth: 16,
itemHeight: 10,
data: ['rose1', 'rose2', 'rose3', 'rose4', 'rose5', 'rose6', 'rose7', 'rose8'],
icon: 'rect',
formatter: (name) => {
return name + '\n' + 10;
},
textStyle: {
lineHeight: 16
}
},
2. 还可以用rich,自定义样式,但是换行仍然使用\n
label: {
// 在文本中,可以对部分文本采用 rich 中定义样式。
// 这里需要在文本中使用标记符号:
// `{styleName|text content text content}` 标记样式名。
// 注意,换行仍是使用 '\n'。
formatter: [
'{a|这段文本采用样式a}',
'{b|这段文本采用样式b}这段用默认样式{x|这段用样式x}'
].join('\n'),
rich: {
a: {
color: 'red',
lineHeight: 10
},
b: {
backgroundColor: {
image: 'xxx/xxx.jpg'
},
height: 40
},
x: {
fontSize: 18,
fontFamily: 'Microsoft YaHei',
borderColor: '#449933',
borderRadius: 4
},
...
}
}