如何利用百度echarts做一个3d柱状图(ets效果),下面web建站小编给大家详细介绍一下实现代码!
实现代码如下:
复制代码const myEcharts = echarts.init(document.getElementById('chart'));
var xData = ["2020", "2021"];
let colorData = [
['#87C53E', '#97D44F'],
['#40CDB9', '#2EAE9C'],
['#2CB8E6', '#0096C7'],
['#2C8CE6', '#1949BF'],
['#1949BF', '#2C61E6'],
['#341EA9', '#4829E4'],
['#6942B0', '#9162DE'],
['#9B40CA', '#BE5CDE'],
['#E18439', '#FFA127'],
['#DF9A37', '#FFC946'],
['#D2CB04', '#FFF95A'],
['#9FE04B', '#CAFF86']
]
let obj = {
'1月': [10, 11],
'2月': [12, 13],
'3月': [8, 10],
'4月': [9, 14],
'5月': [10, 17],
'6月': [9, 13],
'7月': [5, 12],
'8月': [5, 12],
'9月': [5, 12],
'10月': [5, 12],
'11月': [5, 12],
'12月': [5, 12],
}
let testData = [];
let seriesArr = [];
for (let item in obj) {
testData.push(item)
seriesArr.push(obj[item])
}
let lastYear=0;
let thisYear=0;
seriesArr.map((i)=>{
lastYear += parseInt(i[0]);
thisYear += parseInt(i[1]);
})
let sumValue = [lastYear,thisYear];
let option = {
backgroundColor: "#1a2439", //背景色
tooltip: {
show: false,
},
textStyle: {
color: "#C9C9C9",
},
color: ["#74AF2E", "#74AF2E", "#2EAE9C", "#0096C7", "#0279CD", "#1949BF", "#1949BF", '#6942B0', '#9B40CA',
'#E18439', '#DF9A37', '#D2CB04', '#9FE04B', '#9FE04B'
],
legend: {
type: "scroll",
orient: 'vertical',
selectedMode: false, //图例点击失效
right: "10%",
top: "15%",
textStyle: {
color: "#ffffff",
fontSize: 14,
},
},
grid: {
containLabel: true,
left: "10%",
top: "20%",
bottom: "10%",
right: "30%",
},
xAxis: {
type: "category",
data: xData,
axisLine: {
show: false,
lineStyle: {
color: "#B5B5B5",
},
},
axisTick: {
show: false,
},
axisLabel: {
margin: 20, //刻度标签与轴线之间的距离。
textStyle: {
fontFamily: "Microsoft YaHei",
color: "#18BBFF",
},
fontSize: 16,
fontStyle: "bold"
},
},
yAxis: {
type: "value",
axisLine: {
show: false,
lineStyle: {
color: "#B5B5B5",
},
},
splitLine: {
show: true,
lineStyle: {
color: '#466ABA'
}
},
axisLabel: {
textStyle: {
fontFamily: "Microsoft YaHei",
color: "#18BBFF",
},
fontSize: 16,
},
},
series: seriesData(seriesArr)
};
console.log(option)
myEcharts.setOption(option);
function seriesData(data) {
let barData = [];
let pictorialBarData = [];
let countArr = [];
let count = 0;
let count_1 = 0;
let testObj = [];
data.map((item, index) => {
barData.push({
"name": testData[index],
"type": "bar",
data: item,
stack: "zs",
type: "bar",
barMaxWidth: "auto",
barWidth: 50,
itemStyle: {
color: {
x: 0,
y: 0,
x2: 0,
y2: 1,
type: "linear",
global: false,
colorStops: [{
offset: 0,
color: colorData[index][0],
},
{
offset: 1,
color: colorData[index][1],
},
],
},
},
label: {
show: true,
offset: [55, 0]
},
labelLine: {
show: true,
}
});
countArr = [];
count += item[0];
count_1 += item[1];
countArr.push(count, count_1);
pictorialBarData.push({
data: countArr,
type: "pictorialBar",
barMaxWidth: "20",
symbolPosition: "end",
symbol: "diamond",
symbolOffset: [0, "-50%"],
symbolSize: [50, 20],
zlevel: 2,
})
})
let btArr = [{
data: [1, 1],
type: "pictorialBar",
barMaxWidth: "20",
symbol: "diamond",
symbolOffset: [0, "50%"],
symbolSize: [50, 20],
zlevel: 2,
}, {
data: data[0],
type: "pictorialBar",
barMaxWidth: "20",
symbol: "diamond",
symbolOffset: [0, "50%"],
symbolSize: [50, 20],
zlevel: 2,
}];
barData.unshift(
{
name: '总数',
type: 'bar',
barGap: '-100%', // 左移100%,stack不再与上面两个在一列
label: {
normal: {
show: true,
color:'#fff',
position: ['18',-25], // 位置设为top
formatter: '{c}',
textStyle: { color: '#fff' }
}
},
barWidth: 50,
itemStyle: {
normal: {
color: 'rgba(128, 128, 128, 0.3)'// 仍为透明
}
},
data: sumValue,
})
let arr = [...barData, ...btArr, ...pictorialBarData];
console.log('arr', arr)
return arr;
}
- 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
效果图如右上角缩略图
百度echarts雷达图radar根据分数点显示每个不同颜色
百度echarts柱状图/折线图x轴显示全部文本(太长自动换行)
上面是“百度echarts做一个3d柱状图(ets效果)”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_2799.html
workflows工作流
一个外国人在吹奏萨克斯ComfyUI工作流
一个男孩在吃西瓜ComfyUI工作流
一张由表情符号组成的照片ComfyUI工作流
森林里一只空灵的犀鸟ComfyUI工作流
令人着迷的一只老虎ComfyUI工作流
金属埃及人ComfyUI工作流
梦幻向日葵ComfyUI工作流
一尊白玉佛像ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!