[TOC]
一些option配置说明
1. 关于Y轴的特别配置说明
1.1 自动计算的坐标轴最小间隔大小
通过这个设置,可以做到坐标显示只显示整数(设置成1)
yAxis: {
type: 'value',
minInterval: 1,
}
只在数值轴或时间轴中(type: 'value' 或 'time')有效。
官方文档地址:https://echarts.apache.org/zh/option.html#yAxis.minInterval
1.2 Y轴添加单位或者名字
yAxis: {
name: 'Y轴名称',
nameLocation: 'middle', // 'start' | 'middle' | 'end'
nameGap: 30, // 名称与轴线距离
nameTextStyle: {
padding: [10, 20, 30, 40] // 上右下左边距
},
position: 'left', // 坐标轴显示位置
offset: 0 // 坐标轴偏移量
},
2. 柱状图的配置相关
2.1 设置柱状图的宽度
let data = [10, 20, 15, 20, 22, 12]
let option = {
series: [
{
type: 'bar', name: '名字', barGap: 0,
data: data,
barWidth: (() => {
// 大于5条数据,设置宽度为15
if (data.length > 5) {
return 15;
}
return null; // 自适应
})(),
}
]
}