Echarts3d动态柱状图

img

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { getEcharts3DBar } from './getEcharts3DBar';  
import * as echarts from 'echarts'
export default{
methods:{
init3DBar(){
const fn=()=>{
let option=getEcharts3DBar(this.xData,this.yData, '01')
// x轴类型['品类一','品类二',...] y轴数据[32,52,63,52,...], 颜色类型
if (this.endValue == this.xData.length) {
this.endValue = 6;
this.startValue = 0; // 起始点
} else {
this.endValue ++;
this.startValue++
}
option.dataZoom[0].startValue=this.startValue
option.dataZoom[0].endValue=this.endValue
this.myChart.setOption(option);
}
fn()
this.timer= setInterval(fn,3000)
}
}
}

getEcharts3DBar.js

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
export const getEcharts3DBar=function getEcharts3DBar (xAxisData, data, colorType='01') {
var colorArr = [];
if (colorType == '01') {
colorArr = ["#2886c6", "#50bfda", "#89e3ec"];
} else {
colorArr = ["#28c1c6", "#50dac0", "#87e8c7"];
}
var color = {
type: "linear",
x: 0,
x2: 1,
y: 0,
y2: 0,
colorStops: [
{
offset: 0,
color: colorArr[0],
},
{
offset: 0.5,
color: colorArr[0],
},
{
offset: 0.5,
color: colorArr[1],
},
{
offset: 1,
color: colorArr[1],
},
],
};
var barWidth = 30;
var constData = [];
var showData = [];
data.filter(function (item) {
if (item) {
constData.push(1);
showData.push(item);
} else {
constData.push(0);
showData.push(
{
value: 1,
itemStyle: {
normal: {
borderColor: "rgba(0,0,0,0)",
borderWidth: 2,
color: "rgba(0,0,0,0)",
},
},
}
);
}
});
return {
tooltip: {
trigger: "axis",
// formatter: function (params) {
// var str = params[0].axisValue + ":";
// params.filter(function (item) {
// if (item.componentSubType == "bar") {
// str += "<br/>" + item.seriesName + ":" + item.value;
// }
// });
// return str;
// },
},
grid: {
left: "0%", //图表距边框的距离
right: "0%",
top: "10%",
bottom: "12%",
containLabel: false,
},
xAxis: {
data: xAxisData,
axisTick: {
show: true,
},
axisLabel: {
// rotate: '30',
fontSize:10,
show: true,
color:'#fff'
},
},
yAxis: {
splitLine:{
show:true,
lineStyle:{
color:"rgba(255,255,255,.2)"
}
},
axisTick: {
show: false,
},
axisLine: {
show: false,
},
axisLabel: {
show: false,
},
},
dataZoom: [
//滑动条
{
xAxisIndex: 0, //这里是从X轴的0刻度开始
show: false, //是否显示滑动条,不影响使用
type: "slider", // 这个 dataZoom 组件是 slider 型 dataZoom 组件
startValue: 0, // 从头开始。
endValue: 6, // 一次性展示6个。
}],
series: [
{
z: 1,
name: '签到人数',
type: "bar",
barWidth: barWidth,
barGap: "0%",
data: data,
itemStyle: {
normal: {
color: color,
label: {
show: true, //开启显示
position: 'top', //在上方显示
textStyle: { //数值样式
color: '#fff',
fontSize: 12
}}
},
},
},
{
z: 2,
name: '数据',
type: "pictorialBar",
data: constData,
symbol: "diamond",
symbolOffset: ["0%", "50%"],
symbolSize: [barWidth, 10],
itemStyle: {
normal: {
color: color,
},
},
tooltip: {
show: false,
},
},
{
z: 3,
name: '数据',
type: "pictorialBar",
symbolPosition: "end",
data: showData,
symbol: "diamond",
symbolOffset: ["0%", "-50%"],
symbolSize: [barWidth - 4, (10 * (barWidth - 4)) / barWidth],
itemStyle: {
normal: {
borderColor: colorArr[2],
borderWidth: 2,
color: colorArr[2],
},
},
tooltip: {
show: false,
},
},
],
};
}