当前位置:   article > 正文

echarts条形图添加滚动条

echarts条形图添加滚动条

效果展示:
在这里插入图片描述
测试数据:

taskList:[{majorDeptName:'测试',finishCount:54,notFinishCount:21},
{majorDeptName:'测试',finishCount:54,notFinishCount:21},
{majorDeptName:'测试',finishCount:54,notFinishCount:21},
{majorDeptName:'测试',finishCount:54,notFinishCount:21},
{majorDeptName:'测试',finishCount:54,notFinishCount:41},
{majorDeptName:'测试',finishCount:54,notFinishCount:41},
{majorDeptName:'测试',finishCount:54,notFinishCount:41},
{majorDeptName:'测试',finishCount:54,notFinishCount:41},
{majorDeptName:'测试',finishCount:54,notFinishCount:41},]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

代码如下:

   initBarchart(){
          this.barChart = this.$echarts.init(this.$refs.barChart);
        let finishData = [];
        let unFinishData = []
	      let chartName = [];
      if (  this.taskList && this.taskList.length > 0) {
          this.taskList.forEach(item => {
          chartName.push(item.majorDeptName)  
          finishData.push(item.finishCount)
          unFinishData.push(item.notFinishCount)
          })
      }
    
	let max = Math.max.apply(null,finishData.concat(unFinishData));
	let emptyData = finishData.map(function(v, i) {
     let item = {
         value: max,
         label: {   
             formatter: '{a|' + v + '}',
             position: 'right',
           
             rich: {
                 a: {
                     color:'#BFF4FF',
                     fontSize:14,
                     padding:[5, 10]
                 }
             }
         }
     }
     return item
	});
	let emptyData2 = unFinishData.map(function(v, i) {
     let item = {
         value: max,
         label: {  
             formatter: '{a|' + v + '}',
             position: 'right',
             rich: {
                 a: {
                     color:'#BFF4FF',
                     fontSize:14,
                     padding:[5, 10]
                 }
             }
         }
     }
     return item
	});
const barGap = '80%'
	let option = {
       tooltip: {
		    show: true,
		    trigger: 'item',
		},
            
        legend: {
          data: ['已完成','未完成'],
          right:'5%',
          //  itemWidth:15, 
          textStyle:{
          color:'#fff'
        },
        },
       grid: {
           top: '10%',
           right: '15%',
           left: '10%',
           bottom: '5%',
           containLabel: true    
       },
	    xAxis: [
		    {
	            type : 'value',
              position: 'top',
                name: '/个',
	            axisLabel:{      //坐标轴字体颜色
	            	show:false,
	            },
	            axisLine:{
	            	show:false,
	            	lineStyle: {
		                  color: "#218BA0",
		            }
	            },
		        axisTick:{       //y轴刻度线
		            show:false
		        },
	            splitLine:{    //网格
	            	show: false,
	            },
	            max: function(value) {
		            return value.max
		        },
		    }
        ],
	    yAxis: [{
	        type: 'category',
	        data:chartName,
            inverse: true,
	        axisTick:{       //y轴刻度线
	           show:false,
             
	        },

	        axisLabel: {
	            formatter: '{value}',
	            color: '#218BA0',
	            fontSize:14
	        },
        	axisLine: {
        		show:false,
	        },
	        splitLine: {
	            show:false
	        },
	    },
	    {
	        type: "category",
	        name: "",
	        axisTick: {
	            show: false,
               
	        },
	        splitLine: {
	            show: false
	        },
	        axisLabel: {
	            show: false,
	        },
	        axisLine: {
	            show: false
	        },
	        inverse: true,
	        data: chartName
	    }],
	    series: [
	       	{
	            type: 'bar',
              show: true,
	            barWidth: '18%',
	                yAxisIndex: 0,
               barGap,
            	silent:true,
	            itemStyle: {
	                normal: {
	                    color: '#11353d',
	                }
	            },
	            label: {
	                show:true,
	            },
	            data: emptyData
	        },
	        {
	            show: true,
	            type: 'bar',
                barGap,
                 yAxisIndex: 1,
	            barWidth: '18%',
                 name:'已完成',
	            z: 2,
	            label: {
                show: false,
            },
	            itemStyle: {
			      		normal: {
		                color: '#03bae2',
		                barBorderRadius: [0,0],
		            }
	            },
	            data: finishData,
	       	},
	       		{
	            type: 'bar',
                show: true,           
	            barWidth: '18%',
              barGap,
	            yAxisIndex: 0,
            	silent:true,
	            itemStyle: {
	                normal: {
	                    color: '#11353d',
	                    barBorderRadius: [0,0],
	                }
	            },
	            label: {
	                show:true,
	            },
	            data: emptyData2
	        },
	        {
	            show: true,
	            type: 'bar',
	            barWidth: '18%',
              barGap,
                   yAxisIndex: 1,
              name:'未完成',
	            z: 2,
	            label: {
	                show: false,
	            },
	            itemStyle: {
				      	normal: {
		                color:'#e27903' ,
		                barBorderRadius: [0,0],
		            }
	            },
	            data: unFinishData,
	       	}
	    ],
        dataZoom: [
  {
                    yAxisIndex:[0,1],//这里是从X轴的0刻度开始
                    show: false,//是否显示滑动条,不影响使用
                    weight:2,
                    type: 'inside', // 这个 dataZoom 组件是 slider 型 dataZoom 组件
                    startValue: 0,
                    endValue: 3, 
                    zoomOnMouseWheel: false,  // 关闭滚轮缩放
                    moveOnMouseWheel: true, // 开启滚轮平移
                    moveOnMouseMove: true  // 鼠标移动能触发数据窗口平移 
                },
               {
                   yAxisIndex: [0,1],//这里是从X轴的0刻度开始
                    show: false,//是否显示滑动条,不影响使用
                    type: 'slider', // 这个 dataZoom 组件是 slider 型 dataZoom 组件
                    fillerColor: "#0089d1", // 滚动条颜色
                    borderColor: "rgba(17, 100, 210, 0.1)",
                    zoomLock:true, // 是否只平移不缩放
                    handleSize:10, // 两边手柄尺寸
                    width:8,
                    heigh:8,
                
                    bottom: 2,
                    backgroundColor: 'rgba(255,255,255,.4)',
                    brushSelect:false,
                    showDetail:false,
                    showDataShadow:false
                }

  ],
         
	};
   if (  this.taskList && this.taskList.length > 4) {
      option.dataZoom[0].show = true
        option.dataZoom[1].show = tru
     }
    this.barChart.setOption(option)
    },```
  • 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
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/blog/article/detail/51208
推荐阅读
相关标签
  

闽ICP备14008679号