设置yAxis中坐标轴名称的文本样式

2018-09-09 11:58 更新

当我们对 ECharts 图表中的 yAxis 设置了坐标轴名称后,就需要对其文本样式属性做出一些改变,通常情况下您可能会设置 y 坐标轴名称的颜色和字体,而在本节中,我们会提供更多的坐标轴名称的文本样式设置。

yAxis.nameTextStyle   |   Object

该属性是控制 y 坐标轴名称的文字样式。

yAxis.nameTextStyle.color   |   Color

设置 y 坐标轴名称的颜色,默认与 axisLine.lineStyle.color 有相同取值。

yAxis.nameTextStyle.fontStyle   |   string

[ default: 'normal' ]

设置 y 坐标轴名称文字字体的风格。

可以选择:

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

yAxis.nameTextStyle.fontWeight   |   string

[ default: normal ]

控制 y 坐标轴名称文字字体的粗细。

可以选择:

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

yAxis.nameTextStyle.fontFamily   |   string

[ default: 'sans-serif' ]

设置 y 坐标轴名称文字的字体系列。

默认值为'sans-serif' ,还可以是 'serif' , 'monospace', 'Arial', 'Courier New', 'Microsoft YaHei', ...

yAxis.nameTextStyle.fontSize   |   number

[ default: 12 ]

设置 y 坐标轴名称文字的字体大小。

yAxis.nameTextStyle.align   |   string

设置 yAxis 坐标轴名称的文字水平对齐方式,默认自动。

可以选择:

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

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

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

yAxis.nameTextStyle.verticalAlign   |   string

设置 yAxis 坐标轴名称的文字垂直对齐方式,默认自动。

可以选择:

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

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

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

yAxis.nameTextStyle.lineHeight   |   number

设置 yAxis 坐标轴名称的行高。

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

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

yAxis.nameTextStyle.backgroundColor   |   string, Object

[ default: 'transparent' ]

设置文字块背景色。

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

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

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

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

yAxis.nameTextStyle.borderColor   |   string

[ default: 'transparent' ]

设置文字块边框颜色。

yAxis.nameTextStyle.borderWidth   |   number

[ default: 0 ]

设置文字块边框宽度。

yAxis.nameTextStyle.borderRadius   |   number, Array

[ default: 0 ]

设置文字块的圆角。

yAxis.nameTextStyle.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。

yAxis.nameTextStyle.shadowColor   |   string

[ default: 'transparent' ]

设置文字块的背景阴影颜色。

yAxis.nameTextStyle.shadowBlur   |   number

[ default: 0 ]

设置文字块的背景阴影长度。

yAxis.nameTextStyle.shadowOffsetX   |   number

[ default: 0 ]

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

yAxis.nameTextStyle.shadowOffsetY   |   number

[ default: 0 ]

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

yAxis.nameTextStyle.width   |   number, string

设置文字块的宽度。

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

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

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

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

yAxis.nameTextStyle.height   |   number, string

设置文字块的高度。

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

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

yAxis.nameTextStyle.textBorderColor   |   string

[ default: 'transparent' ]

设置坐标轴名称文字本身的描边颜色。

yAxis.nameTextStyle.textBorderWidth   |   number

[ default: 0 ]

设置坐标轴名称文字本身的描边宽度。

yAxis.nameTextStyle.textShadowColor   |   string

[ default: 'transparent' ]

设置坐标轴名称文字本身的阴影颜色。

yAxis.nameTextStyle.textShadowBlur   |   number

[ default: 0 ]

设置坐标轴名称文字本身的阴影长度。

yAxis.nameTextStyle.textShadowOffsetX   |   number

[ default: 0 ]

设置坐标轴名称文字本身的阴影 X 偏移。

yAxis.nameTextStyle.textShadowOffsetY   |   number

[ default: 0 ]

设置坐标轴名称文字本身的阴影 Y 偏移。

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

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号