var datas = [ { value: 100, name: 'Chengdu', }, { value: 96, name: 'Guangzhou', }, { value: 89, name: 'Shanghai', }, { value: 75, name: 'Beijing', }, { value: 56, name: 'Hangzhou', }, { value: 29, name: 'Shaoxing', }, ]; var maxArr = new Array(datas.length).fill(100); option = { backgroundColor: '#000', grid: { left: 20, right:80, bottom: 50, top:20, containLabel: true, }, tooltip: { trigger: 'item', axisPointer: { type: 'none', }, formatter: function (params) { return params.data.name + ' : ' + params.data.value; }, }, xAxis: { show: false, type: 'value', }, yAxis: [ { type: 'category', inverse: true, axisLabel: { show: true, align: 'right', textStyle: { fontSize: 14, color: 'rgba(255,255,255,0.5)', rich: { name: { padding: [0,10,0,20], width:50, borderWidth:1, align: 'left', }, }, }, formatter: (name) => { var index = datas.map((item) => item.name).indexOf(name) + 1; return [ '{' + 'index' + '|' +'NO.'+ index + '}', '{name|' + name + '}', ].join(''); }, }, splitLine: { show: false, }, axisTick: { show: false, }, axisLine: { show: false, }, data: datas.map((item) => item.name), }, { type:'category', inverse: true, axisLabel:{ show:true, margin:30,//右侧y轴数字的外边距 textStyle: { fontSize: 14, color: 'rgba(255,255,255,0.5)', }, formatter: (value) => { return value +'万元' }, }, splitLine: { show: false, }, axisTick: { show: false, }, axisLine: { show: false, }, data: datas.map((item) => { console.log('item',item) return item.value }), } ], series: [ { name: '值', type: 'bar', zlevel: 1, showBackground: true, // 柱状条上方的白色线条 label: { show: true, position: 'right', // 位置 color: '#fff', fontSize: 19, fontWeight:'bold', distance: -1, // 字与条形图bar 的距离 formatter: '|', // 这里是数据展示的时候显示的数据 }, itemStyle: { normal: { color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [ { offset: 0, color: '#5A3FFF', }, { offset: 1, color: '#1ED6FF', }, ]), }, }, barWidth: 20, data: datas, }, ], };