效果图如下:
代码:
const animationDuration = 1500
const barName = ['销售管理部', '生产技术部', '研发部', '质量管理部', '总经办', '采购供应部', '人力资源部', '综合管理部', '财务部']
const rzData= [34, 26, 17, 17, 4, 4, 4, 4, 2]
const lzData= [34, 26, 17, 17, 4, 4, 4, 4, 2]
this.chart.setOption({
color: ['#2ec7c9', '#ED7D31', '#5ab1ef'],
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
legend: {
left: 'center',
top: '0',
},
grid: [
{
show: false,
left: '3%',
top: '30',
bottom: '0%',
containLabel: true,
width: '38%'
},
{
show: false,
left: '51.5%',
top: '30',
bottom: '6%',
width: '0%'
},
{
show: false,
right: '3%',
top: '30',
bottom: '0%',
containLabel: true,
width: '38%'
}
],
xAxis: [
{
name: '人数',
type: 'value',
inverse: true, // 强制设置坐标轴分割间隔
axisLine: {
// 坐标轴轴线相关设置
show: true, // 是否显示坐标轴轴线
onZero: true, // X 轴或者 Y 轴的轴线是否在另一个轴的 0 刻度上
lineStyle: {
color: '#ECEDF0'
}
},
axisTick: {
show: true
},
position: 'bottom',
axisLabel: {
show: true,
color: '#c6d3d7',
fontSize: 12,
fontFamily: 'DINPro-Regular'
},
splitLine: {
show: false
}
},
{
gridIndex: 1,
show: false
},
{
gridIndex: 2,
axisLine: {
show: true, // 是否显示坐标轴轴线
onZero: true, // X 轴或者 Y 轴的轴线是否在另一个轴的 0 刻度上
lineStyle: {
color: '#ECEDF0'
}
},
axisTick: {
show: true
},
position: 'bottom',
axisLabel: {
show: true,
color: '#c6d3d7',
fontSize: 12,
fontFamily: 'DINPro-Regular'
},
splitLine: {
show: false
}
}
],
yAxis: [
{
type: 'category',
inverse: true,
position: 'right',
axisLine: {
show: true,
lineStyle: {
color: '#606266'
}
},
axisTick: {
show: false
},
axisLabel: {
show: false
},
data: barName
},
{
gridIndex: 1,
type: 'category',
inverse: true,
position: 'left',
axisLine: {
show: false
},
axisTick: {
show: false
},
axisLabel: {
show: true,
textStyle: {
color: '#606266',
fontSize: 12,
fontFamily: 'pmzd_title'
},
align: 'center'
},
data: barName.map(function(value) {
return {
value: value,
textStyle: {
align: 'center'
}
}
})
},
{
gridIndex: 2,
type: 'category',
inverse: true,
position: 'left',
axisLine: {
show: true,
lineStyle: {
color: '#606266'
}
},
axisTick: {
show: false
},
axisLabel: {
show: false
},
data: barName
}
],
series: [
{
name: '入职',
type: 'bar',
itemStyle: {
normal: {
label: {
show: true, // 开启显示
position: 'left', // 在上方显示
textStyle: {
// 数值样式
// color: colors[0].borderColor,
color: '#606266',
fontSize: 12
}
},
borderWidth: 1
}
},
data: rzData,
animationDuration
},
{
name: '离职',
type: 'bar',
xAxisIndex: 2,
yAxisIndex: 2,
itemStyle: {
normal: {
label: {
show: true, // 开启显示
position: 'right', // 在上方显示
textStyle: {
// 数值样式
color: '#606266',
fontSize: 12
},
},
borderWidth: 1
}
},
data: lzData,
animationDuration
}
]
})