geo组件文本标签设置

2018-09-25 11:42 更新

geo.label   |   Object

图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等,label 选项在 ECharts 2.x 中放置于itemStyle.normal下,在 ECharts 3 中为了让整个配置项结构更扁平合理,label 被拿出来跟 itemStyle 平级,并且跟 itemStyle 一样拥有 normal, emphasis 两个状态。

geo.label.normal   |   Object

使用 normal 设置 geo 组件的文本标签

geo.label.normal.show   |   boolean

[ default: false ]

是否显示标签。

geo.label.normal.position   |   string, Array

标签的位置。

可选:

  • [x, y]通过相对的百分比或者绝对像素值表示标签相对于图形包围盒左上角的位置。 示例:
    // 绝对的像素值
     position: [10, 10], 
    // 相对的百分比
     position: ['50%', '50%']
  • 'top'
  • 'left'
  • 'right'
  • 'bottom'
  • 'inside'
  • 'insideLeft'
  • 'insideRight'
  • 'insideTop'
  • 'insideBottom'
  • 'insideTopLeft'
  • 'insideBottomLeft'
  • 'insideTopRight'
  • 'insideBottomRight'

参见:label position

geo.label.normal.distance   |   number

[ default: 5 ]

距离图形元素的距离。当 position 为字符描述值(如 'top'、'insideRight')时候有效。

参见:label position

geo.label.normal.rotate   |   number

标签旋转。从 -90 度到 90 度。正值是逆时针。

参见:label rotation

geo.label.normal.offset   |   Array

是否对文字进行偏移。默认不偏移。例如:[30, 40] 表示文字在横向上偏移 30,纵向上偏移 40。

geo.label.normal.formatter   |   string, Function

标签内容格式器,支持字符串模板和回调函数两种形式,字符串模板与回调函数返回的字符串均支持用 \n 换行。

字符串模板

模板变量有 {a}、{b}、{c},分别表示系列名,数据名,数据值。

示例:

formatter: '{b}: {c}'

回调函数

回调函数格式:

(params: Object|Array) => string

参数 params 是 formatter 需要的单个数据集。格式如下:

{
    componentType: 'series',
    // 系列类型
    seriesType: string,
    // 系列在传入的 option.series 中的 index
    seriesIndex: number,
    // 系列名称
    seriesName: string,
    // 数据名,类目名
    name: string,
    // 数据在传入的 data 数组中的 index
    dataIndex: number,
    // 传入的原始数据项
    data: Object,
    // 传入的数据值
    value: number|Array,
    // 数据图形的颜色
    color: string,

}

geo.label.normal.color   |   Color

[ default: "#fff" ]

文字的颜色。

如果设置为 'auto',则为视觉映射得到的颜色,如系列色。

geo.label.normal.fontStyle   |   string

[ default: 'normal' ]

文字字体的风格

可选:

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

geo.label.normal.fontWeight   |   string

[ default: normal ]

文字字体的粗细

可选:

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

geo.label.normal.fontFamily   |   string

[ default: 'sans-serif' ]

文字的字体系列

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

geo.label.normal.fontSize   |   number

[ default: 12 ]

文字的字体大小

geo.label.normal.align   |   string

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

可选:

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

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

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

geo.label.normal.verticalAlign   |   string

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

可选:

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

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

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

geo.label.normal.lineHeight   |   number

文本标签的行高。

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

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

geo.label.normal.backgroundColor   |   string, Object

[ default: 'transparent' ]

文字块背景色。

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

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

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

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

如果设置为 'auto',则为视觉映射得到的颜色,如系列色。

geo.label.normal.borderColor   |   string

[ default: 'transparent' ]

文字块边框颜色。

如果设置为 'auto',则为视觉映射得到的颜色,如系列色。

geo.label.normal.borderWidth   |   number

[ default: 0 ]

文字块边框宽度。

geo.label.normal.borderRadius   |   number, Array

[ default: 0 ]

文字块的圆角。

geo.label.normal.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。

geo.label.normal.shadowColor   |   string

[ default: 'transparent' ]

文字块的背景阴影颜色。

geo.label.normal.shadowBlur   |   number

[ default: 0 ]

文字块的背景阴影长度。

geo.label.normal.shadowOffsetX   |   number

[ default: 0 ]

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

geo.label.normal.shadowOffsetY   |   number

[ default: 0 ]

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

geo.label.normal.width   |   number, string

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

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

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

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

geo.label.normal.height   |   number, string

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

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

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

geo.label.normal.textBorderColor   |   string

[ default: 'transparent' ]

文字本身的描边颜色。

如果设置为 'auto',则为视觉映射得到的颜色,如系列色。

geo.label.normal.textBorderWidth   |   number

[ default: 0 ]

文字本身的描边宽度。

geo.label.normal.textShadowColor   |   string

[ default: 'transparent' ]

文字本身的阴影颜色。

geo.label.normal.textShadowBlur   |   number

[ default: 0 ]

文字本身的阴影长度。

geo.label.normal.textShadowOffsetX   |   number

[ default: 0 ]

文字本身的阴影 X 偏移。

geo.label.normal.textShadowOffsetY   |   number

[ default: 0 ]

文字本身的阴影 Y 偏移。

下一节的内容中,我们将来介绍如何通过富文本样式来设置地理坐标系组件的文本标签。


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号