菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻

ECharts xAxis配置 类目标签的富文本样式

原创
05/13 14:22 更新

xAxis.data[i].textStyle.rich   |   Object

在 xAxis 的 rich 里面,您可以对其富文本样式进行自定义。

在标签中,很多丰富的效果都是通过利用富文本样式得到的。

例如下面的一段代码:

label: {
    normal: {
        // 在文本中,可以对部分文本采用 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
            },
            ...
        }
    }
}

xAxis.data[i].textStyle.rich.<user defined style name>   |   Object

用户可以自定义富文本标签的样式(样式的名字由用户自行获取)

xAxis.data[i].textStyle.rich.<user defined style name>.color   |   Color

[ default: “#fff” ]

用户对 xAxis 中富文本标签的文字颜色进行设置。

xAxis.data[i].textStyle.rich.<user defined style name>.fontStyle   |   string

[ default: ‘normal’ ]

用户对 xAxis 中富文本标签的文字字体风格进行设置。

可供选择的类型:

  • ‘normal’
  • ‘italic’
  • ‘oblique’

xAxis.data[i].textStyle.rich.<user defined style name>.fontWeight   |   string

[ default: normal ]

设置富文本标签文字字体的粗细。

可以选择的类型:

  • ‘normal’
  • ‘bold’
  • ‘bolder’
  • ‘lighter’
  • 100 | 200 | 300 | 400…

xAxis.data[i].textStyle.rich.<user defined style name>.fontFamily   |   string

[ default: ‘sans-serif’ ]

设置富文本标签文字的字体系列

富文本标签中的字体类型还可以是: ‘serif’ , ‘monospace’, ‘Arial’, ‘Courier New’, ‘Microsoft YaHei’, …

xAxis.data[i].textStyle.rich.<user defined style name>.fontSize   |   number

[ default: 12 ]

设置富文本标签中文字的字体大小

xAxis.data[i].textStyle.rich.<user defined style name>.align   |   string

富文本标签中文字水平对齐方式的设置,默认情况下是自动的。

可以选择:

  • ‘left’
  • ‘center’
  • ‘right’

但是 rich 中如果没有设置 align,则会取父层级的 align。

例如:

{
    align: right,
    rich: {
        a: {
            // 没有设置 `align`,则 `align` 为 right
        }
    }
}

xAxis.data[i].textStyle.rich.<user defined style name>.verticalAlign   |   string

设置富文本标签文字的垂直对齐方式,默认自动。

可以选择的类型:

  • ‘top’
  • ‘middle’
  • ‘bottom’

rich 中如果没有设置 verticalAlign,则会取父层级的 verticalAlign。

例如:

{
    verticalAlign: bottom,
    rich: {
        a: {
            // 没有设置 `verticalAlign`,则 `verticalAlign` 为 bottom
        }
    }
}

xAxis.data[i].textStyle.rich.<user defined style name>.lineHeight   |   number

行高。

rich 中如果没有设置 lineHeight,则会取父层级的 lineHeight。例如:

{
    lineHeight: 56,
    rich: {
        a: {
            // 没有设置 `lineHeight`,则 `lineHeight` 为 56
        }
    }
}

xAxis.data[i].textStyle.rich.<user defined style name>.backgroundColor   |   string, Object

[ default: ‘transparent’ ]

设置富文本标签中文字块的背景色。

此处的颜色值可以直接列出,例如:’#123234’, ‘red’, rgba(0,23,11,0.3)’。

当然,也支持使用图片,例如:

backgroundColor: {
    image: 'xxx/xxx.png'
    // 这里可以是图片的 URL,
    // 或者图片的 dataURI,
    // 或者 HTMLImageElement 对象,
    // 或者 HTMLCanvasElement 对象。
}

当使用图片的时候,可以使用 width 或 height 指定高宽,也可以不指定,让其自适应。`

xAxis.data[i].textStyle.rich.<user defined style name>.borderColor   |   string

[ default: ‘transparent’ ]

对 xAxis 中富文本标签的文字块边框颜色进行设置。

xAxis.data[i].textStyle.rich.<user defined style name>.borderWidth   |   number

[ default: 0 ]

设置富文本标签的文字块边框宽度。

xAxis.data[i].textStyle.rich.<user defined style name>.borderRadius   |   number, Array

[ default: 0 ]

设置富文本标签的文字块圆角。

xAxis.data[i].textStyle.rich.<user defined style name>.padding   |   number, Array

[ default: 0 ]

设置富文本标签文字块的内边距。例如:

  • padding: [3, 4, 5, 6]:表示 [上, 右, 下, 左] 的边距。
  • padding: 4 :表示 padding: [4, 4, 4, 4]。
  • padding: [3, 4]:表示 padding: [3, 4, 3, 4]。

注意,文字块的 width 和 height 指定的是内容高宽,不包含 padding。

xAxis.data[i].textStyle.rich.<user defined style name>.shadowColor   |   string

[ default: ‘transparent’ ]

设置富文本标签文字块的背景阴影颜色。

xAxis.data[i].textStyle.rich.<user defined style name>.shadowBlur   |   number

[ default: 0 ]

设置富文本标签文字块的背景阴影长度。

xAxis.data[i].textStyle.rich.<user defined style name>.shadowOffsetX   |   number

[ default: 0 ]

设置富文本标签文字块的背景阴影 X 偏移量。

xAxis.data[i].textStyle.rich.<user defined style name>.shadowOffsetY   |   number

[ default: 0 ]

设置富文本标签文字块的背景阴影 Y 偏移量。

xAxis.data[i].textStyle.rich.<user defined style name>.width   |   number, string

设置富文本标签文字块的宽度。

一般情况下不用指定,不指定则默认为文字的宽度。在想做表格项或者使用图片(参见 backgroundColor)时,可能会使用它。

注意,文字块的 width 和 height 指定的是内容高宽,不包含 padding。

width 也可以是百分比字符串,如 ‘100%’,表示的是所在文本块的 contentWidth(即不包含文本块的 padding)的百分之多少。之所以以 contentWidth 做基数,因为每个文本片段只能基于 content box 布局。如果以 outerWidth 做基数,则百分比的计算在实用中不具有意义,可能会超出。

注意,如果不定义 rich 属性,则不能指定 width 和 height。`

xAxis.data[i].textStyle.rich.<user defined style name>.height   |   number, string

设置富文本标签中文字块的高度。

一般不用指定,不指定则默认是文字的高度。在使用图片(参见 backgroundColor)时,可能会使用它。

注意,文字块的 width 和 height 指定的是内容高宽,不包含 padding。

注意,如果不定义 rich 属性,则不能指定 width 和 height。

xAxis.data[i].textStyle.rich.<user defined style name>.textBorderColor   |   string

[ default: ‘transparent’ ]

对 xAxis 中富文本标签文字本身的描边颜色进行设置。

xAxis.data[i].textStyle.rich.<user defined style name>.textBorderWidth   |   number

[ default: 0 ]

设置富文本标签的文字本身的描边宽度。

xAxis.data[i].textStyle.rich.<user defined style name>.textShadowColor   |   string

[ default: ‘transparent’ ]

设置富文本标签的文字本身的阴影颜色。

xAxis.data[i].textStyle.rich.<user defined style name>.textShadowBlur   |   number

[ default: 0 ]

设置富文本标签的文字本身的阴影长度。

xAxis.data[i].textStyle.rich.<user defined style name>.textShadowOffsetX   |   number

[ default: 0 ]

设置富文本标签的文字本身的阴影 X 偏移。

xAxis.data[i].textStyle.rich.<user defined style name>.textShadowOffsetY   |   number

[ default: 0 ]

设置富文本标签的文字本身的阴影 Y 偏移。

综合评分:9.9 评分 请对本文进行纠错,及学习过程中有困难疑惑可在此进行讨论