动画参考 https://echarts.apache.org/examples/zh/editor.html?c=bar-animation-delay
const option = {
backgroundColor: '#062e65',
stack: true,
grid: { bottom: 0, top: 0, left: 0, right: 0 },
xAxis: {
data: [],
silent: true,
splitLine: { show: false },
axisLine: { show: false }
},
yAxis: {
silent: true,
splitLine: { show: false },
axisLine: { show: false },
axisTick: { show: false },
axisLabel: { show: false }
},
series: [
{
type: 'bar',
data: [ // building
40, 41.3, 42, 42.6, 43.5, 44, 44.5, 44.6, 44.7, 44.7, 44.6, 44.5, 44,
43.5, 42.6, 42, 41.3, 0, 30, 30, 30, 34, 34, 34, 34, 34, 0, 13, 13, 13,
15, 31, 15, 13, 13, 13, 48, 48, 48, 48, 48, 48, 48, 5, 5, 5, 5, 5, 5, 5,
15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 12.3, 13, 13.6, 14.5, 15, 15.5,
15.6, 15.7, 15.7, 15.6, 15.5, 15, 14.5, 13.6, 13, 12.3, 0, 9, 9, 9, 9,
9, 9, 9, 48, 47.5, 47, 46.5, 46, 45.5, 45, 45, 45, 45, 45, 0, 23, 24,
25, 26, 27, 26, 25, 24, 23, 0, 48, 49, 50, 51, 52, 51, 50, 49, 48, 38.3,
39, 39.6, 40.5, 41, 41.5, 41.6, 41.7, 41.7, 41.6, 41.5, 41, 40.5, 39.6,
39, 38.3, 0, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 0, 4.3, 5, 5.6,
6.5, 7, 7.5, 7.6, 7.7, 7.7, 7.6, 7.5, 7, 6.5, 5.6, 5, 4.3
],
itemStyle: { normal: { color: 'rgb(38, 41, 57)' } },
animationDelay: function (idx) {
return idx * 10;
},
zlevel: 2, // 最前面的图层
},
{
type: 'bar',
data: [ // building2
56, 64, 56, 48, 48, 40, 32, 32, 47.3, 47.3, 47.4, 45.5, 46, 46.5, 49.4,
50, 50.7, 0, 9, 9, 9, 7, 7, 7, 5, 5, 39, 0, 39, 38.5, 36, 19.5, 35,
36.5, 36, 35.5, 48, 47.5, 20.5, 21, 21.5, 22, 22.5, 66, 66.5, 67, 67.5,
68, 0, 12, 2, 3, 6, 23, 8, 7, 8, 9, 15, 16, 9.7, 9, 8.4, 3.5, 3, 2.5, 0,
12.3, 12.3, 12.4, 12.5, 13, 14, 15.4, 16.5, 17.7, 30.5, 22, 66, 66, 66,
68, 84, 68, 27, 27.5, 28, 0, 46, 45.5, 45, 44.5, 44, 43.5, 43, 43, 20,
19, 18, 47, 46, 47, 48, 49, 50, 73, 0, 22, 21.5, 21, 20.5, 20, 19.5, 19,
18.5, 18, 17.5, 19, 19, 19, 17, 17, 17, 19, 19, 19, 15, 16.5, 18.4, 20,
21.7, 59, 41, 39, 37, 0
],
zlevel: 1,
itemStyle: { normal: { color: 'rgb(28, 31, 47)' } },
animationDelay: function (idx) {
return idx * 10 + 300
},
}
],
animationEasing: 'elasticOut',
animationDelayUpdate: function (idx) {
return idx * 5;
}
};
生成 series.data
const roofs = [
[1, 2, 3, 4, 5, 4, 3, 2, 1], // 三角形
[2, 2, 2, 4, 4, 4, 2, 2, 2], // 凸出的形状
[2, 2, 2, 4, 20, 4, 2, 2, 2],
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
[6, 6, 6, 6, 6, 5, 4, 3, 2, 1],
[ 0.3, 1, 1.6, 2.5, 3, 3.5, 3.6, 3.7, 3.7, 3.6, 3.5, 3, 2.5, 1.6, 1, 0.3],
[6, 6, 6, 6, 6, 2, 2, 2],
[6, 5.5, 5, 4.5, 4, 3.5, 3, 2.5, 2, 1.5],
[1, 1, 1, 1, 1, 1.5, 2, 2.5, 3, 3.5, 4],
[1, 1, 1, 1, 1, 1, 1],
[4, 4, 4, 2, 2, 2, 4, 4, 4],
];
function build(height) {
let arr = [100]
let l = 14
let h = height || 50
function addFloor(arr, l) {
const a = []
for (let i = 0;i < arr.length;i++) {
a.push(arr[i] + l)
}
return a
}
for (let i = 0;i < l;i++) {
const newRoof = addFloor(roofs[r(11)], r(h))
if (Math.random() < 0.5) {
newRoof.reverse()
}
arr = arr.concat(newRoof)
if (Math.random() < 0.5) {
arr.push(0)
}
}
return arr
}
const building = build()
const building2 = (function () {
let b = build(100)
for (let i = 0;i < b.length;i++) {
if (b[i] > building[i]) {
b[i] = b[i] - building[i]
}
}
return b
})()