options.js
5.84 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-09-14 14:08:14
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-10-12 14:58:59
* @FilePath: \scrm-micro-home\src\components\options.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import * as echarts from 'echarts'
import util from '@/utils/util'
function getLineOptions(obj) {
const { color, lineList } = obj
// const statDate = dataList.map(item => item.statDate)
const dataList = lineList.map(item => +item.ordinateValue || +item.output || 0)
console.log(dataList, 'dataList')
// 定义颜色渐变
var gradientColors = [
{
offset: 0, // 渐变起始位置
color: color[0] // 渐变起始颜色
},
{
offset: 1, // 渐变结束位置
color: color[1] // 渐变结束颜色
}
]
const num = dataList.map((item, index) => {
return {
value: item,
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, gradientColors) // 设置渐变色
}
}
}
})
console.log(num)
var options = {
xAxis: {
type: 'category',
axisLabel: {
show: false // 隐藏 y 轴坐标标签
},
axisTick: {
show: false // 隐藏 y 轴刻度线
},
data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
},
grid: {
bottom: 0,
top: 0
},
yAxis: {
type: 'value',
axisLabel: {
show: false // 隐藏 y 轴坐标标签
},
splitLine: false,
axisTick: {
show: false // 隐藏 y 轴刻度线
}
},
series: [
{
barWidth: '50%', // 柱条宽度
data: num,
// itemStyle: {
// normal: {
// color: new echarts.graphic.LinearGradient(0, 0, 0, 1, gradientColors) // 设置渐变色
// }
// },
type: 'bar'
}
]
}
return options
}
function getLineOddOptions(obj) {
const { color, lineList } = obj
console.log(obj)
// const statDate = dataList.map(item => item.statDate)
const dataList = lineList.map(item => item.saleAmount)
const dataX = lineList.map(item => item.aggregateTime)
// 定义颜色渐变
var gradientColors1 = [
{
offset: 0, // 渐变起始位置
color: color[0] // 渐变起始颜色
},
{
offset: 1, // 渐变结束位置
color: color[1] // 渐变结束颜色
}
]
var gradientColors2 = [
{
offset: 0, // 渐变起始位置
color: color[2] // 渐变起始颜色
},
{
offset: 1, // 渐变结束位置
color: color[3] // 渐变结束颜色
}
]
const num = dataList.map((item, index) => {
return {
value: item
// itemStyle: {
// normal: {
// color: new echarts.graphic.LinearGradient(0, 0, 0, 1, index % 2 == 0 ? gradientColors1 : gradientColors2) // 设置渐变色
// }
// }
}
})
var options = {
xAxis: {
type: 'category',
// axisLabel: {
// show: false // 隐藏 y 轴坐标标签
// },
axisTick: {
show: false // 隐藏 y 轴刻度线
},
data: dataX
},
tooltip: {
trigger: 'axis', // 设置触发类型为坐标轴轴线触发
axisPointer: {
type: 'line' // 设置指示器类型为直线
},
formatter: function(params) {
const value = params[0].value
return `销售额<br><b>¥${util.formatNumber(value)}</b>`
}
},
grid: {
bottom: '10%',
top: '8%'
},
// 其他配置项...
dataZoom: [
{
type: 'slider', // 显示滑动条
xAxisIndex: 0, // 指定水平拖动的 x 轴索引
start: 0, // 初始的数据窗口范围的起始位置
end: 100 // 初始的数据窗口范围的结束位置
// dataBackground: {
// lineStyle: {
// width: 10, // 滑动柱的宽度
// color: '#ff0000' // 滑动柱的颜色
// }
// }
}
],
yAxis: {
type: 'value',
axisLabel: {
formatter: function(value) {
if (value === 0) {
return ''
} else {
return value
}
}
}
},
series: [
{
barWidth: '35%', // 柱条宽度
data: num,
// itemStyle: {
// normal: {
// color: new echarts.graphic.LinearGradient(0, 0, 0, 1, gradientColors) // 设置渐变色
// }
// },
type: 'line',
areaStyle: {
color: 'rgba(211, 208, 255, 1)' // 设置面积颜色和透明度
}
}
]
}
return options
}
function getPieOptions(obj) {
console.log(obj, 888)
const color = obj.map(item => item.color)
const dataList = obj.map(item => {
return {
value: item.saleAmount
}
})
var options = {
color,
series: [
{
name: '',
type: 'pie',
// center: ['50%', '53%'],
radius: ['60%', '80%'],
label: {
show: false, // 不显示标签
position: 'center'
},
emphasis: {
scale: true, // 不放大扇区,
label: {
show: true,
formatter: function(params) {
return '{a|销售额}\n{b|¥' + util.formatNumber(params.value) + '}'
},
rich: {
a: {
fontSize: 12,
lineHeight: 24
},
b: {
fontSize: 20,
lineHeight: 30
}
}
}
},
labelLine: {
show: false // 不显示标签引导线
},
data: dataList
}
]
}
return options
}
export default { getLineOptions, getLineOddOptions, getPieOptions }