setOptiontitle
主副标题。有 text 或 subtext 才会显示。默认顶部居中。
调用
ts
chart.setOption({
title: {
show: true,
text: '距离修正后的回波信号(532)',
subtext: '2024-10-07 11:12 — 2024-10-08 11:12'
}
})换行写 \n。show: false 时不画、不占位,可用 getTitle() 取文字后自己画。
字段
| 字段 | 说明 | 类型 | 可选值 | 默认 |
|---|---|---|---|---|
show | 是否显示 | boolean | true / false | true |
text | 主标题。有文字才会显示 | string | — | — |
subtext | 副标题 | string | — | — |
x | 水平位置。关键字、像素或百分比 | string / number | left / center / right | center |
y | 垂直位置。关键字、像素或百分比 | string / number | top / bottom / center | top |
backgroundColor | 标题背景 | string | — | transparent |
borderWidth | 边框线宽,像素 | number | — | 0 |
borderColor | 边框颜色 | string | — | transparent |
padding | 内边距。数字、[上下, 左右] 或 [上, 右, 下, 左]。百分比相对容器 | number / string / array | — | 8 |
itemGap | 各行间距,像素 | number | — | 8 |
label | 主标题文字样式 | object | — | 见下表 |
sublabel | 副标题文字样式 | object | — | 见下表 |
padding 可以是数字、[上下, 左右] 或 [上, 右, 下, 左]。百分比相对图表容器(左右相对宽,上下相对高)。
label / sublabel
| 字段 | 说明 | 类型 | 可选值 | 默认 |
|---|---|---|---|---|
fontFamily | 字体 | string | — | sans-serif |
fontSize | 字号,像素 | number | — | 14 |
fontStyle | 字体样式 | string | normal / italic / oblique | normal |
fontWeight | 字重。也可写数字 | string / number | normal / bold / bolder / lighter | normal |
color | 文字颜色。主标题 #111827,副标题 #6b7280 | string | — | 见左 |
lineHeight | 行高,无单位倍率 | number | — | 1 |
padding | 文字内边距 | number / string / array | — | 0 |
format | 自定义文字。返回值按 HTML 写入 | function | — | 原文 |
ts
title: {
text: '距离修正后的回波信号(532)',
label: {
format: value => `<b>${value}</b>`,
},
}