| | |
| | | this.barOption = { |
| | | tooltip: { |
| | | trigger: 'axis', |
| | | formatter: function (params) { |
| | | formatter: function(params) { |
| | | const dataParams = params[1]; |
| | | return `${dataParams.name}<br/>数值:${dataParams.value}`; |
| | | // 获取当前柱子的颜色(取渐变色的起始色) |
| | | let color; |
| | | if (dataParams.dataIndex === 0) { |
| | | color = '#FFEF00'; |
| | | } else if (dataParams.dataIndex === 1) { |
| | | color = '#00FFC3'; |
| | | } else if (dataParams.dataIndex === 2) { |
| | | color = '#00DBFF'; |
| | | } else { |
| | | color = '#057BFF'; |
| | | } |
| | | return `${dataParams.name}<br/><span style="display:inline-block;width:8px;height:8px;border-radius:50%;background-color:${color};margin-right:6px;"></span>${dataParams.value}`; |
| | | }, |
| | | backgroundColor: 'rgba(0,0,0,0.7)', |
| | | borderColor: '#00ffff', |
| | | backgroundColor: '#ffffff', |
| | | borderWidth: 1, |
| | | textStyle: { |
| | | color: '#fff', |
| | | color: '#333333', |
| | | fontSize: 14 |
| | | } |
| | | }, |
| | | padding: [8, 12] |
| | | }, |
| | | grid: { |
| | | top: '10%', |
| | |
| | | xAxis: { |
| | | type: 'category', |
| | | data: sortedData.map(item => item[0]), |
| | | axisTick: { |
| | | show: false // 隐藏刻度线 |
| | | }, |
| | | axisLine: { |
| | | lineStyle: { |
| | | color: 'rgba(30, 44, 88, 1)' |
| | | } |
| | | }, |
| | | axisTick: { |
| | | show: false |
| | | }, |
| | | axisLabel: { |
| | | color: '#ffffff', |
| | |
| | | symbolOffset: [0, 0], |
| | | symbolBoundingData: yAxisMax, |
| | | z: 2, |
| | | data: sortedData.map(item => item[1]), |
| | | itemStyle: { |
| | | color: function (params) { |
| | | return params.dataIndex === 0 ? '#ffd700' : '#00ffff'; |
| | | data: sortedData.map((item, index) => ({ |
| | | value: item[1], |
| | | itemStyle: { |
| | | color: index === 0 ? new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [ |
| | | { offset: 0, color: '#FFEF00' }, |
| | | { offset: 0.5, color: '#C86A01' }, |
| | | { offset: 1, color: '#402303' } |
| | | ]) : index === 1 ? new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [ |
| | | { offset: 0, color: '#00FFC3' }, |
| | | { offset: 1, color: '#008570' } |
| | | ]) : index === 2 ? new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [ |
| | | { offset: 0, color: '#00DBFF' }, |
| | | { offset: 1, color: '#0093A8' } |
| | | ]) : new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [ |
| | | { offset: 0, color: '#05DBFF' }, |
| | | { offset: 0.5, color: '#057BFF' }, |
| | | { offset: 1, color: '#030E3F' } |
| | | ]) |
| | | } |
| | | } |
| | | })) |
| | | } |
| | | ] |
| | | }; |