BarOption.js
2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* @Description: 柱状图配置
* @Author: huyue
* @Date: 2023-07-07 14:04:52
* @LastEditors: huyue
* @LastEditTime: 2023-09-12 11:04:03
*/
import * as echarts from 'echarts'
function getBarOptions(obj, colorList, isMultiple, barwidth, formatYAxis) {
const barWidth = barwidth || '14'
const multiple = isMultiple || false
// const { tooltipFormatter } = obj
var barLineOption = {
// tooltip: {
// trigger: 'axis',
// borderWidth: 0,
// padding: 0,
// formatter: tooltipFormatter || '',
// confine: true
// },
xAxis: {
data: []
},
barWidth: barWidth,
yAxis: {
name: '',
type: 'value',
// min: 0,
// max: 100,
splitLine: {
lineStyle: {
color: '#1d2a38'
}
},
splitNumber: 4,
axisLabel: {
// 这种做法就是在y轴的数据的值旁边拼接单位,貌似也挺方便的
formatter: function(value) {
if (formatYAxis) {
return `${value / 10000}万`
} else {
return value
}
}
}
},
grid: {
left: '0',
right: '4%',
top: '20%',
bottom: '4%',
containLabel: true
},
series: [
{
name: 'bar',
type: 'bar',
data: [],
label: {
show: true,
position: 'top',
color: '#fff',
fontSize: 8
},
itemStyle: {
barBorderRadius: [2, 2, 0, 0], // 柱体圆角
color: function(params) {
var colorItem = []
if (multiple) {
colorItem = params.dataIndex % 2 === 0 ? colorList[0] : colorList[1]
}
return new echarts.graphic.LinearGradient(
0, 0, 0, 1, [{ // 代表渐变色从正上方开始
offset: 0, // offset范围是0~1,用于表示位置,0是指0%处的颜色
color: multiple ? colorItem[0] : colorList[0]
}, // 柱图渐变色
{
offset: 0.5, // 指100%处的颜色
color: multiple ? colorItem[1] : colorList[1]
},
{
offset: 1, // 指100%处的颜色
color: multiple ? colorItem[2] : colorList[2]
}]
)
}
}
}
]
}
return barLineOption
}
export default getBarOptions