initEventBarLine() {
let myChart = echarts.init(this.$refs.barlinechart1);
let eventDataOneAll = [40, 40]
let barOne1 = [8, 5]
let barOne2 = [10, 4]
let barOne3 = [8, 6]
let barOne4 = [8, 10]
let barOneSum1 = []
barOne1.forEach((ele, index) => {
barOneSum1.push(ele + barOne2[index])
})
let barOneSum2 = []
barOne3.forEach((ele, index) => {
barOneSum2.push(ele + barOneSum1[index])
})
let barOneSum3 = []
barOne4.forEach((ele, index) => {
barOneSum3.push(ele + barOneSum2[index])
})
let eventDataTwoAll = [40, 40]
let barTwo1 = [4, 7]
let barTwo2 = [6, 8]
let barTwo3 = [8, 4]
let barTwo4 = [12, 5]
let barTwoSum1 = []
barTwo1.forEach((ele, index) => {
barTwoSum1.push(ele + barTwo2[index])
})
let barTwoSum2 = []
barTwo3.forEach((ele, index) => {
barTwoSum2.push(ele + barTwoSum1[index])
})
let barTwoSum3 = []
barTwo4.forEach((ele, index) => {
barTwoSum3.push(ele + barTwoSum2[index])
})
let option;
option = {
animation: true,
animationDuration: 5000,
tooltip: {
trigger: "axis",
axisPointer: {
type: "cross",
label: {
backgroundColor: "#6a7985",
fontSize: 20,
},
},
},
xAxis: [
{
type: "category",
data: ["火灾", "交通"],
axisLine: {
show: true,
lineStyle: {
color: "#fff",
width: 2,
},//隐藏y轴
},
axisLabel: {
show: true,
color: '#fff',
fontSize: 20,
interval: 0
},
axisTick: {
show: false, // 是否显示坐标轴刻度
},
},
{
show: false,
type: "category",
data: ["", ""],
},
{
show: false,
type: "category",
data: ["", ""],
},
],
grid: {
top: "12%",
left: "40",
bottom: "12%",
right: "4%",
},
legend: {
show: false,
textStyle: {
fontSize: 20,//字体大小
color: '#fff'//字体颜色
},
right: 30,
itemWidth: 28,
itemHeight: 14,
},
yAxis: {
name: "单位: 次",
type: "value",
nameGap: '14',
nameTextStyle: {//y轴上方单位的颜色
color: '#FFD200',
fontSize: 20,
fontFamily: 'fashionsimp'
},
max: 40,
axisLabel: {
show: true,
interval: 0, // 使x轴文字显示全
color: '#fff',
fontSize: 20
},
axisLine: {
show: true,
lineStyle: {
color: "#fff",
width: 2,
}, //隐藏y轴
},
axisTick: {
show: false, // 是否显示坐标轴刻度
},
splitLine: {//分割线配置
show: true,
lineStyle: {
color: '#213965',
}
}
},
series: [
{
z: 0,
name: '2022',
type: 'bar',
data: eventDataOneAll,
itemStyle: {
borderWidth: 0,
borderColor: 'rgba(11,94,148,1)',
color: 'rgba(255,175,2,.3)'
},
xAxisIndex: 0,
barWidth: 26, //柱子宽度
tooltip:{
show:false
},
},
//第一个柱子
{
z: 1,
name: '特别重大',
type: 'bar',
barWidth: 26,
xAxisIndex: 1,
stack: 'Search',
itemStyle: {
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(242, 46, 16, 1)' }, //柱图渐变色
{ offset: 0.5, color: 'rgba(249, 107, 44, 1)' }, //柱图渐变色
{ offset: 0.6, color: 'rgba(242, 46, 16, 1)' }, //柱图渐变色
{ offset: 1, color: 'rgba(249, 107, 44, 1)' }, //柱图渐变色
]
)
},
data: barOne1
},
// 第一个柱子头部盖子
{
z: 1,
name: "特别重大",
data: barOne1,
type: 'pictorialBar',
symbol: 'diamond',
symbolPosition: 'end',
xAxisIndex: 2,
symbolOffset: [-16, -4],
symbolSize: [26, 8],
tooltip:{
show:false
},
zlevel: 2,
itemStyle: {
normal: {
// color: '#d6cccc'
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(183, 84, 165, 1)' },
{ offset: 0.5, color: 'rgba(226, 170, 217, 0.99)' },
{ offset: 0.6, color: 'rgba(183, 84, 165, 1)' },
{ offset: 1, color: 'rgba(226, 170, 217, 0.99)' },
]
)
}
}
},
// 第一个柱子底部盖子
{
z: 1,
name: "特别重大",
data: barOne1,
type: 'pictorialBar',
symbol: 'diamond',
symbolPosition: 'start',
xAxisIndex: 2,
symbolOffset: [-16, 3],
symbolSize: [26, 8],
zlevel: 2,
tooltip:{
show:false
},
itemStyle: {
normal: {
// color: '#E7BAC0',
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(242, 46, 16, 1)' }, //柱图渐变色
{ offset: 0.5, color: 'rgba(249, 107, 44, 1)' }, //柱图渐变色
{ offset: 0.6, color: 'rgba(242, 46, 16, 1)' }, //柱图渐变色
{ offset: 1, color: 'rgba(249, 107, 44, 1)' }, //柱图渐变色
]
)
}
}
},
// 第一根柱子的第2个
{
z: 2,
name: '重大',
type: 'bar',
barWidth: 26,
stack: 'Search',
xAxisIndex: 2,
itemStyle: {
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(183, 84, 165, 1)' }, //柱图渐变色
{ offset: 0.5, color: 'rgba(226, 170, 217, 0.99)' }, //柱图渐变色
{ offset: 0.6, color: 'rgba(183, 84, 165, 1)' }, //柱图渐变色
{ offset: 1, color: 'rgba(226, 170, 217, 0.99)' }, //柱图渐变色
]
)
},
data: barOne2,
},
// 第一根柱子的第2个盖子
{
z: 1,
name: "重大",
data: barOneSum1,
type: 'pictorialBar',
symbol: 'diamond',
symbolPosition: 'end',
xAxisIndex: 2,
symbolOffset: [-16, -4],
symbolSize: [26, 8],
zlevel: 2,
tooltip:{
show:false
},
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(255, 178, 30, 1)' },
{ offset: 0.5, color: 'rgba(255, 232, 107, 1)' },
{ offset: 0.6, color: 'rgba(255, 178, 30, 1)' },
{ offset: 1, color: 'rgba(255, 232, 107, 1)' },
]
)
}
}
},
// 第一根柱子的第3个
{
z: 2,
name: '较大',
type: 'bar',
barWidth: 26,
stack: 'Search',
xAxisIndex: 2,
itemStyle: {
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(255, 178, 30, 1)' }, //柱图渐变色
{ offset: 0.5, color: 'rgba(255, 232, 107, 1)' }, //柱图渐变色
{ offset: 0.6, color: 'rgba(255, 178, 30, 1)' }, //柱图渐变色
{ offset: 1, color: 'rgba(255, 232, 107, 1)' }, //柱图渐变色
]
)
},
data: barOne3,
},
// 第一根柱子的第3个盖子
{
z: 1,
name: "较大",
data: barOneSum2,
type: 'pictorialBar',
symbol: 'diamond',
symbolPosition: 'end',
xAxisIndex: 2,
symbolOffset: [-16, -4],
symbolSize: [26, 8],
zlevel: 2,
tooltip:{
show:false
},
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(113, 163, 243, 1)' }, //柱图渐变色
{ offset: 0.5, color: 'rgba(164, 196, 247, 1)' }, //柱图渐变色
{ offset: 0.6, color: 'rgba(113, 163, 243, 1)' }, //柱图渐变色
{ offset: 1, color: 'rgba(164, 196, 247, 1)' }, //柱图渐变色
]
)
}
}
},
// 第一根柱子的第4个
{
z: 2,
name: '一般',
type: 'bar',
barWidth: 26,
stack: 'Search',
xAxisIndex: 2,
itemStyle: {
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(113, 163, 243, 1)' },
{ offset: 0.5, color: 'rgba(164, 196, 247, 1)' },
{ offset: 0.6, color: 'rgba(113, 163, 243, 1)' },
{ offset: 1, color: 'rgba(164, 196, 247, 1)' },
]
)
},
data: barOne4,
},
// 第一根柱子的第4个盖子
{
z: 1,
name: "一般",
data: barOneSum3,
type: 'pictorialBar',
symbol: 'diamond',
symbolPosition: 'end',
xAxisIndex: 2,
tooltip:{
show:false
},
symbolOffset: [-16, -4],
symbolSize: [26, 8],
zlevel: 2,
itemStyle: {
normal: {
color: '#9AB6D8'
}
}
},
//第二根柱子
{
z: 0,
name: '2023',
type: 'bar',
tooltip:{
show:false
},
data: eventDataTwoAll,
itemStyle: {
borderWidth: 0,
borderColor: 'rgba(164,114,43,1)',
color: 'rgba(61,195,255,.3)'
},
xAxisIndex: 0,
barWidth: 26, //柱子宽度
},
{
z: 1,
name: '特别重大',
type: 'bar',
barWidth: 26,
xAxisIndex: 1,
stack: 'plan',
itemStyle: {
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(242, 46, 16, 1)' }, //柱图渐变色
{ offset: 0.5, color: 'rgba(249, 107, 44, 1)' }, //柱图渐变色
{ offset: 0.6, color: 'rgba(242, 46, 16, 1)' }, //柱图渐变色
{ offset: 1, color: 'rgba(249, 107, 44, 1)' }, //柱图渐变色
]
)
},
data: barTwo1
},
// 第二根柱子头部盖子
{
z: 1,
name: "特别重大",
data: barTwo1,
type: 'pictorialBar',
symbol: 'diamond',
symbolPosition: 'end',
xAxisIndex: 2,
symbolOffset: [16, -4],
symbolSize: [26, 8],
zlevel: 2,
tooltip:{
show:false
},
itemStyle: {
normal: {
// color: '#d6cccc'
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(183, 84, 165, 1)' },
{ offset: 0.5, color: 'rgba(226, 170, 217, 0.99)' },
{ offset: 0.6, color: 'rgba(183, 84, 165, 1)' },
{ offset: 1, color: 'rgba(226, 170, 217, 0.99)' },
]
)
}
}
},
// 第二根柱子底部盖子
{
z: 1,
name: "特别重大",
data: barTwo1,
type: 'pictorialBar',
symbol: 'diamond',
symbolPosition: 'start',
xAxisIndex: 2,
symbolOffset: [16, 3],
symbolSize: [26, 8],
zlevel: 2,
tooltip:{
show:false
},
itemStyle: {
normal: {
// color: '#E7BAC0',
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(242, 46, 16, 1)' }, //柱图渐变色
{ offset: 0.5, color: 'rgba(249, 107, 44, 1)' }, //柱图渐变色
{ offset: 0.6, color: 'rgba(242, 46, 16, 1)' }, //柱图渐变色
{ offset: 1, color: 'rgba(249, 107, 44, 1)' }, //柱图渐变色
]
)
}
}
},
// 第二根柱子的第2个
{
z: 2,
name: '重大',
type: 'bar',
barWidth: 26,
stack: 'plan',
xAxisIndex: 2,
itemStyle: {
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(183, 84, 165, 1)' }, //柱图渐变色
{ offset: 0.5, color: 'rgba(226, 170, 217, 0.99)' }, //柱图渐变色
{ offset: 0.6, color: 'rgba(183, 84, 165, 1)' }, //柱图渐变色
{ offset: 1, color: 'rgba(226, 170, 217, 0.99)' }, //柱图渐变色
]
)
},
data: barTwo2,
},
// 第二根柱子的第2个盖子
{
z: 1,
name: "重大",
data: barTwoSum1,
type: 'pictorialBar',
symbol: 'diamond',
symbolPosition: 'end',
xAxisIndex: 2,
tooltip:{
show:false
},
symbolOffset: [16, -4],
symbolSize: [26, 8],
zlevel: 2,
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(255, 178, 30, 1)' },
{ offset: 0.5, color: 'rgba(255, 232, 107, 1)' },
{ offset: 0.6, color: 'rgba(255, 178, 30, 1)' },
{ offset: 1, color: 'rgba(255, 232, 107, 1)' },
]
)
}
}
},
// 第二根柱子的第3个
{
z: 2,
name: '较大',
type: 'bar',
barWidth: 26,
stack: 'plan',
xAxisIndex: 2,
itemStyle: {
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(255, 178, 30, 1)' }, //柱图渐变色
{ offset: 0.5, color: 'rgba(255, 232, 107, 1)' }, //柱图渐变色
{ offset: 0.6, color: 'rgba(255, 178, 30, 1)' }, //柱图渐变色
{ offset: 1, color: 'rgba(255, 232, 107, 1)' }, //柱图渐变色
]
)
},
data: barTwo3,
},
// 第二根柱子的第3个盖子
{
z: 1,
name: "较大",
data: barTwoSum2,
type: 'pictorialBar',
symbol: 'diamond',
symbolPosition: 'end',
xAxisIndex: 2,
tooltip:{
show:false
},
symbolOffset: [16, -4],
symbolSize: [26, 8],
zlevel: 2,
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(113, 163, 243, 1)' }, //柱图渐变色
{ offset: 0.5, color: 'rgba(164, 196, 247, 1)' }, //柱图渐变色
{ offset: 0.6, color: 'rgba(113, 163, 243, 1)' }, //柱图渐变色
{ offset: 1, color: 'rgba(164, 196, 247, 1)' }, //柱图渐变色
]
)
}
}
},
// 第二根柱子的第4个
{
z: 2,
name: '一般',
type: 'bar',
barWidth: 26,
stack: 'plan',
xAxisIndex: 2,
itemStyle: {
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{ offset: 0, color: 'rgba(113, 163, 243, 1)' },
{ offset: 0.5, color: 'rgba(164, 196, 247, 1)' },
{ offset: 0.6, color: 'rgba(113, 163, 243, 1)' },
{ offset: 1, color: 'rgba(164, 196, 247, 1)' },
]
)
},
data: barTwo4,
},
// 第二根柱子的第4个盖子
{
z: 1,
name: "一般",
tooltip:{
show:false
},
data: barTwoSum3,
type: 'pictorialBar',
symbol: 'diamond',
symbolPosition: 'end',
xAxisIndex: 2,
symbolOffset: [16, -4],
symbolSize: [26, 8],
zlevel: 2,
itemStyle: {
normal: {
color: '#9AB6D8'
}
}
},
]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
},
代码看上去有点多,但是原理很简单,要主要是柱子的样式代码较多, 拆开来看的话,就是平常的二维柱子然后给柱子顶部加一个‘盖子就行啦’,盖子可以是菱形,也可以是圆形,如果是圆形的盖子,显示的效果就变成圆柱体啦!实在看不懂的,复制代码一个一个配置,边改边看!下课!