echarts自定义胶囊柱图并设置每个柱子的渐变色
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | drawCharts() { let myChart = echarts.init(document.getElementById( 'main' )); let option = { tooltip: { trigger: 'axis' , axisPointer: { type: 'line' } }, grid: { left: '3%' , right: '4%' , bottom: '3%' , containLabel: true }, xAxis: { type: 'value' , splitLine:{ //坐标轴在grid区域的分割线 show: false }, axisLabel:{ show: false } }, yAxis: [ { type: 'category' , data: [ '日发电' , '月发电' , '年发电' ], inverse: true , axisTick: { alignWithLabel: true , show: false }, axisLine:{ show: false } }, { type: 'category' , data: [1000, 1000, 1000], inverse: true , axisTick: { alignWithLabel: true , show: false }, axisLine:{ show: false }, axisLabel:{ textStyle:{ fontSize:12, color: "#fff" } } } ], series: [ { name: '数据' , type: 'bar' , yAxisIndex:0, data: [10, 52, 20], barWidth: '38%' , label:{ show: true , position: 'top' , formatter: function (params){ return params.data+ "%" ; } }, // 设置每个柱子的渐变色 itemStyle: { borderRadius:[0, 0, 50, 0], color: function (params){ let colorList = [ [ '#0B42A7' , '#209CFF' ], [ '#068054' , '#0DB484' ], [ '#C86A05' , '#E9B500' ], ] let colorItem = colorList[params.dataIndex] return new echarts.graphic.LinearGradient(0,0,1,0, [ { offset: 0, color: colorItem[0] }, { offset: 1, color: colorItem[1] } ], false ) } } }, { name: '' , type: 'bar' , yAxisIndex:1, //使两个柱状图重合的效果 barWidth: '40%' , data: [100, 100, 100, 100, 100,100, 100], label:{ show: false }, itemStyle:{ color: "none" , borderColor: "#143670" , borderWidth:2, borderRadius:[0, 0, 50, 0], }, } ] } myChart.setOption(option); }, onSelectChange(selectedRowKeys) { if (selectedRowKeys.length > 4) { this .$message.warning( '最多只能选择4条缺陷!' ) return } this .selectedRowKeys = selectedRowKeys }, } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架