要使 Echart 标题居中,可以将 left、right 和 top 属性设置为“center”,如下所示:
option = {
title: {
text: 'My Chart Title',
left: 'center', // center horizontally
top: 'top' // align with top of the chart
},
// other chart options
}
通过设置 left: ‘center’,标题将在图表区域中水平居中。
您还可以使用 right: ‘center’ 使标题垂直居中。
此外,您可以使用 textAlign 属性来控制标题中的文本对齐方式。 例如:
option = {
title: {
text: 'My Chart Title',
left: 'center', // center horizontally
top: 'top', // align with top of the chart
textStyle: {
textAlign: 'center' // center text within the title
}
},
// other chart options
}
通过设置 textStyle: { textAlign: ‘center’ },标题中的文本也将水平居中。