JSRUN 用代码说话

设置时间轴的文本标签

编辑教程

设置ECharts时间轴的文本标签

timeline.label

Object

设置 ECharts 时间轴的文本标签。

ECharts 时间轴文本标签的状态有两个: normal 和 emphasis。normal 是文本正常的样式,emphasis 是文本高亮的样式,比如鼠标悬浮或者图例联动高亮的时候会使用 emphasis 作为文本的样式。

timeline.label.normal

Object

在 normal 状态下设置 ECharts 时间轴文本标签。

timeline.label.normal.position

string, number [ 默认值 'auto' ]

时间轴文本标签的位置。

可选的配置方式:

  • 'auto': 完全自动决定。
  • 'left': 贴左边界放置。 当 timline.orient 为 'vertical' 时有效。
  • 'right':当 timline.orient 为 'vertical' 时有效。 贴右边界放置。
  • 'top': 贴上边界放置。 当 timline.orient 为 'horizontal' 时有效。
  • 'bottom': 贴下边界放置。 当 timline.orient 为 'horizontal' 时有效。
  • number: 指定某个数值时,表示 label 和轴的距离。为 0 时则和坐标轴重合,可以为正负值,决定 label 在坐标轴的哪一边。

timeline.label.normal.show

boolean [ 默认值 true ]

是否显示 label。

timeline.label.normal.interval

string, number [ 默认值 'auto' ]

label 的间隔。当指定为数值时,例如指定为 2,则每隔两个显示一个 label。

timeline.label.normal.rotate

prefix [ 默认值 0 ]

label 的旋转角度。正值表示逆时针旋转。

timeline.label.normal.formatter

string, Function [ 默认值 null ]

刻度标签的内容格式器,支持字符串模板和回调函数两种形式。

示例:

// 使用字符串模板,模板变量为刻度默认标签 {value}
formatter: '{value} kg'

// 使用函数模板,函数参数分别为刻度数值(类目),刻度的索引
formatter: function (value, index) {
    // 格式化成月/日,只在第一个刻度显示年份
    var date = new Date(value);
    var texts = [(date.getMonth() + 1), date.getDate()];
    if (index === 0) {
        texts.unshift(date.getYear());
    }
    return texts.join('/');
}

timeline.label.normal.color

Color [ 默认值 '#304654' ]

timeline.lable.normal文字的颜色。

timeline.label.normal.fontStyle

string [ 默认值 'normal' ]

timeline.lable.normal文字字体的风格

可选:

  • 'normal'
  • 'italic'
  • 'oblique'

timeline.label.normal.fontWeight

string [ 默认值 normal ]

timeline.lable.normal文字字体的粗细

可选:

  • 'normal'
  • 'bold'
  • 'bolder'
  • 'lighter'
  • 100 | 200 | 300 | 400...

timeline.label.normal.fontFamily

string [ 默认值 'sans-serif' ]

timeline.lable.normal文字的字体系列

还可以是 'serif' , 'monospace', 'Arial', 'Courier New', 'Microsoft YaHei', ...

timeline.label.normal.fontSize

number [ 默认值 12 ]

timeline.lable.normal文字的字体大小

timeline.label.normal.align

string

文字水平对齐方式,默认自动。

可选:

  • 'left'
  • 'center'
  • 'right'

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

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

timeline.label.normal.verticalAlign

string

文字垂直对齐方式,默认自动。

可选:

  • 'top'
  • 'middle'
  • 'bottom'

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

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

timeline.label.normal.lineHeight

number

时间轴文本标签的行高。

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

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

timeline.label.normal.backgroundColor

string, Object [ 默认值 'transparent' ]

文字块背景色。

可以是直接的颜色值,例如:'#123234', 'red', rgba(0,23,11,0.3)'。

可以支持使用图片,例如:

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

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

timeline.label.normal.borderColor

string [ 默认值 'transparent' ]

文字块边框颜色。

timeline.label.normal.borderWidth

number [ 默认值 0 ]

文字块边框宽度。

timeline.label.normal.borderRadius

number, Array [ 默认值 0 ]

文字块的圆角。

timeline.label.normal.padding

number, Array [ 默认值 0 ]

文字块的内边距。例如:

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

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

timeline.label.normal.shadowColor

string [ 默认值 'transparent' ]

文字块的背景阴影颜色。

timeline.label.normal.shadowBlur

number [ 默认值 0 ]

文字块的背景阴影长度。

timeline.label.normal.shadowOffsetX

number [ 默认值 0 ]

文字块的背景阴影 X 偏移。

timeline.label.normal.shadowOffsetY

number [ 默认值 0 ]

文字块的背景阴影 Y 偏移。

timeline.label.normal.width

number, string

文字块的宽度。一般不用指定,不指定则自动是文字的宽度。在想做表格项或者使用图片(参见 backgroundColor)时,可能会使用它。

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

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

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

timeline.label.normal.height

number, string

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

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

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

timeline.label.normal.textBorderColor

string [ 默认值 'transparent' ]

文字本身的描边颜色。

timeline.label.normal.textBorderWidth

number [ 默认值 0 ]

文字本身的描边宽度。

timeline.label.normal.textShadowColor

string [ 默认值 'transparent' ]

文字本身的阴影颜色。

timeline.label.normal.textShadowBlur

number [ 默认值 0 ]

文字本身的阴影长度。

timeline.label.normal.textShadowOffsetX

number [ 默认值 0 ]

文字本身的阴影 X 偏移。

timeline.label.normal.textShadowOffsetY

number [ 默认值 0 ]

文字本身的阴影 Y 偏移。

timeline.label.normal.rich

Object

在 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
            },
            ...
        }
    }
}

timeline.label.emphasis

Object

在 emphasis 状态下设置 ECharts 时间轴文本标签。

timeline.label.emphasis.show

boolean [ 默认值 true ]

是否显示 label。

timeline.label.emphasis.interval

string, number [ 默认值 'auto' ]

label 的间隔。当指定为数值时,例如指定为 2,则每隔两个显示一个 label。

timeline.label.emphasis.rotate

prefix [ 默认值 0 ]

label 的旋转角度。正值表示逆时针旋转。

timeline.label.emphasis.formatter

string, Function [ 默认值 null ]

刻度标签的内容格式器,支持字符串模板和回调函数两种形式。

示例:

// 使用字符串模板,模板变量为刻度默认标签 {value}
formatter: '{value} kg'

// 使用函数模板,函数参数分别为刻度数值(类目),刻度的索引
formatter: function (value, index) {
    // 格式化成月/日,只在第一个刻度显示年份
    var date = new Date(value);
    var texts = [(date.getMonth() + 1), date.getDate()];
    if (index === 0) {
        texts.unshift(date.getYear());
    }
    return texts.join('/');
}

timeline.label.emphasis.color

Color [ 默认值 '#c23531' ]

timeline.lable.emphasis文字的颜色。

timeline.label.emphasis.fontStyle

string [ 默认值 'normal' ]

timeline.lable.emphasis文字字体的风格

可选:

  • 'normal'
  • 'italic'
  • 'oblique'

timeline.label.emphasis.fontWeight

string [ 默认值 normal ]

timeline.lable.emphasis文字字体的粗细

可选:

  • 'normal'
  • 'bold'
  • 'bolder'
  • 'lighter'
  • 100 | 200 | 300 | 400...

timeline.label.emphasis.fontFamily

string [ 默认值 'sans-serif' ]

timeline.lable.emphasis文字的字体系列

还可以是 'serif' , 'monospace', 'Arial', 'Courier New', 'Microsoft YaHei', ...

timeline.label.emphasis.fontSize

number [ 默认值 12 ]

timeline.lable.emphasis文字的字体大小

timeline.label.emphasis.align

string

文字水平对齐方式,默认自动。

可选:

  • 'left'
  • 'center'
  • 'right'

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

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

timeline.label.emphasis.verticalAlign

string

文字垂直对齐方式,默认自动。

可选:

  • 'top'
  • 'middle'
  • 'bottom'

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

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

timeline.label.emphasis.lineHeight

number

emphasis 状态下时间轴文本标签的行高。

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

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

timeline.label.emphasis.backgroundColor

string, Object [ 默认值 'transparent' ]

文字块背景色。

可以是直接的颜色值,例如:'#123234', 'red', rgba(0,23,11,0.3)'。

可以支持使用图片,例如:

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

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

timeline.label.emphasis.borderColor

string [ 默认值 'transparent' ]

文字块边框颜色。

timeline.label.emphasis.borderWidth

number [ 默认值 0 ]

文字块边框宽度。

timeline.label.emphasis.borderRadius

number, Array [ 默认值 0 ]

文字块的圆角。

timeline.label.emphasis.padding

number, Array [ 默认值 0 ]

文字块的内边距。例如:

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

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

timeline.label.emphasis.shadowColor

string [ 默认值 'transparent' ]

文字块的背景阴影颜色。

timeline.label.emphasis.shadowBlur

number [ 默认值 0 ]

文字块的背景阴影长度。

timeline.label.emphasis.shadowOffsetX

number [ 默认值 0 ]

文字块的背景阴影 X 偏移。

timeline.label.emphasis.shadowOffsetY

number [ 默认值 0 ]

文字块的背景阴影 Y 偏移。

timeline.label.emphasis.width

number, string

文字块的宽度。一般不用指定,不指定则自动是文字的宽度。在想做表格项或者使用图片(参见 backgroundColor)时,可能会使用它。

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

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

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

timeline.label.emphasis.height

number, string

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

注意,文字块的 width 和 height 指定的是内容高宽,不包含 padding。 注意,如果不定义 rich 属性,则不能指定 width 和 height。

timeline.label.emphasis.textBorderColor

string [ 默认值 'transparent' ]

文字本身的描边颜色。

timeline.label.emphasis.textBorderWidth

number [ 默认值 0 ]

文字本身的描边宽度。

timeline.label.emphasis.textShadowColor

string [ 默认值 'transparent' ]

文字本身的阴影颜色。

timeline.label.emphasis.textShadowBlur

number [ 默认值 0 ]

文字本身的阴影长度。

timeline.label.emphasis.textShadowOffsetX

number [ 默认值 0 ]

文字本身的阴影 X 偏移。

timeline.label.emphasis.textShadowOffsetY

number [ 默认值 0 ]

文字本身的阴影 Y 偏移。

timeline.label.emphasis.rich

Object

在 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
            },
            ...
        }
    }
}
JSRUN闪电教程系统是国内最先开创的教程维护系统, 所有工程师都可以参与共同维护的闪电教程,让知识的积累变得统一完整、自成体系。 大家可以一起参与进共编,让零散的知识点帮助更多的人。
X
支付宝
9.99
无法付款,请点击这里
金额: 0
备注:
转账时请填写正确的金额和备注信息,到账由人工处理,可能需要较长时间
如有疑问请联系QQ:565830900
正在生成二维码, 此过程可能需要15秒钟