可滚动的横向柱状图,可展示一个,也可以展示多个,颜色,文字,是否渐变等都可展示。
相关组件代码:
<template>
<!-- 柱状图 横向滚动柱状图 -->
<div :id="histogramId" v-bind:style="{height:height,width:width}"></div>
</template>
<script type="text/ecmascript-6">
export default {
props:{
histogramId:{
type:String,
default:''
},
//组件的高度
height: {
type: String,
default: '230px'
},
//组件的宽度
width: {
type: String,
default: '100%'
},
barWidth:{ //柱子的宽度
type:Number,
default:8
},
barBorderRadius:{ //柱子的radius
type:Array,
default:()=>[0,0,0,0]
},
//grid的设置修改
grid:{
type:Object,
default:()=>{
return{
bottom:10,
top:10,
left:10,
right:0
}
}
},
colors:{ //非渐变下的数组颜色
type:Array,
default:()=>['#4BAAF7','#FFBA27','#F55150','#17DACC','#17DA45']
},
colorsJian:{ //渐变下的数组颜色设置
type:Array,
default:()=>[
['rgba(255,255,255,0.1)','#4BAAF7'],['rgba(255,255,255,0.1)','#FFBA27'],
['rgba(255,255,255,0.1)','#F55150'],['rgba(255,255,255,0.1)','#17DACC'],
['rgba(255,255,255,0.1)','#17DA45']
]
},
isJian:{ //颜色是否时渐变模式
type:Boolean,
default:false
},
isSingleColor:{ //是否单条数据多个颜色
type:Boolean,
default:true
},
bgBar:{
type:String,
default:'rgba(128, 164, 229, 0.2)'
},
isShowNumber:{ //是否展示排名
type:Boolean,
default:true
},
showNum:{ //开始展示几条数据
type:Number,
default:4
},
yAxis:{ //相关的yAxis的变量
type:Object,
default:()=>{
return{
axisTickShow:false,
axisLineShow:false,
axisLineColor:'#4BAAF7',
splitLineShow:false,
splitLineColor:'#4BAAF7',
splitLineType:'', //dashed是虚线
axisLabelShow:false,
axisLabelColor:'#ffffff',
axisLabelSize:12,
axisLabelLineHeight:28,
axisLabelPadding:[0,20,0,0]
}
}
},
xAxis:{ //相关的xAxis的变量
type:Object,
default:()=>{
return{
axisTickShow:false,
axisLineShow:false,
axisLineColor:'#4BAAF7',
splitLineShow:false,
splitLineColor:'#4BAAF7',
splitLineType:'', //dashed是虚线
}
}
},
numberImg:{ //排名的图片
type:Array,
default:()=>[
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADYAAAAaCAYAAAD8K6+QAAAAAXNSR0IArs4c6QAACJRJREFUWEfVmNuLZFcVxvdae59zqqovc8kgQSRikMBkSh98EB8EH/RBMaIvRjRBY7xERzMgIsQoOgMmBFSIIokk6EgSMUSSmEwcI6ioEARFRKjMgOCDf4DjdHd11Tln772WfGuf6u4Z4x/QBafPrU71/tX3fWuv2nTmV7vqDr7Uub0LOMbJ6pqdDNdW++He3vuGh1V1/9nVNTn47LX3Dz5fjsv9g5uNw7b/ffba59URwC48cP9lVVGRrJqz4sHD9CIiR94Tsyciprd88OxJOnNxV1968P5LWZLmFFVSJ7Kv2aHgY0eOQ8M+VOQ50KkPnL2V7r1oir0qsQWYpNTCMIcCaH+Q5EIYAYy5GtGp286eont/uasvPnDfLPdLibEVyb2oHC4wYnLsa66qEft6zKduOzelL17Y1QsP3TfLsZUcO0nxkCoGqKphX4345PvOTekLF+Z68dtfn2m3UIqtUGrVS6ZKnaudUlChyik1mqlyOHbUiFDtlCvJNHJiW63CI2zDccCzTh2rEvTPRJodaXRee3LaOS89kXbEsnSs0bF2TLiukVl657S39+Kevc/2iUgjkSbHDudmR2IXqtqgQj3iW97zjSmdfmGuL3/3mzPtdw2MU6cMMKeuMiiDoLrAUBgG3ihgDYgmmrl2whMVxrWRy1y5TJU4ojJbuMzOBpMUg/TSEmPTFsc2cC9dAdWevCRH2uM6s+0BuYLClxAduUys4pxjJud9w8EUG/Ob3/21KZ3+xVx//fC5mfYLdQbWKosMaqmBGQDUkn3QkQAiU0OZJznz2CmPJNNYM1RjAENtcs7YcNRjQEQKKIAsycsCYFBKAeYNrCOyYwOBkqZWeRafkQweDigvInYeVRGKVQ3f/K6vTunzz8/1N9//1kzjQqnvhHKrlLMbOSU/wDRmRQw0m2qVFMuNFEBCI8m8rolHmv1YAJbNmgEmGeqQEKxFUEOXsN8AhX3LUA0Aw569r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UmNFMUKNYc7C3IRv4hXfucN1E9ZG03D5wrR6fd1WB0LrF2y2uJew6H2NN7kerlipzGWvxBBfKIqNANe+3FVpvfNpO2Nus7nNtlivFYu3qQIFO8/gyn9X1opQDGCBF664bkzX37+hzz314EQzFsEI2a6AIe4x2BHAihWjPeA797q68ZfVANup1uqmWg5dAYNlZ3X1amzlERcwKgm53lXxhbbqTk9HLeBeaqsI1baTx4oEOV3ASpAoqwzJmBXhwbsrD2t9b0UXuHrDtWO67kcb+vzTD00kR5HUScrx3Nen19DgwrjsBjC2nsPah8f0sfvW9R+/feRZkaSSoojsvuVcGCM+n1GQMcyuWJHZkVv90FH66L3r+s8/PP6ciqjkiJ2qYc18Pn/xArkHqciW2XoiZqKV919NH/nhuv7rmSefx54btuAUW3AXyHjPdxhla2LYeiNE2PJ7j9C1d6+XfcTZxuTepuTcZum514eNz92NTeTBbG9rbpNzmJX3bZye18bqvk3a/ZusJXuG67vnuyuBvUfxH3F6BVlxM/RQAAAAAElFTkSuQmCC'
]
},
dataObj:{ //相关数据的整理
type:Object,
default:()=>{
return{
name:['活力邻里','活力队伍','活力组织','活力服务','活力发展'],
// name:['活力邻里'],
xData:['天水社区','悦来社区','金融港社区','很多社区','金水社区','哈哈社区','丽日社区'],
data1:[65,55,60,25,45,50,30],
data2:[30,50,20,55,10,40,35],
data3:[45,25,35,12,5,15,5],
data4:[66,44,33,25,77,22,11],
data5:[33,11,22,45,15,10,33]
}
}
}
},
data(){
return{
surveyInit:'',
BgDataData:[]
}
},
methods:{
initMoreColorZhu(){
let that=this;
var allData = that.allData
//整理数据
var typeData = this.dataObj.name
var leftData = that.dataObj.xData,yData = [], maxData = [];
function sumArr(arr){
var result = [];
for(var i = 0;i<arr.length;i++){
var subArr = arr[i];
var subResult = []
for(var j = 0;j<subArr.length;j++){
var current = subArr[j]
var previous = result[i-1] ? result[i-1][j] : 0;
var sum = current + previous;
subResult.push(sum)
}
result.push(subResult)
}
//subResult是返回最大的求和数组值
return subResult
};
var squares = new Array();
for(var v = 0; v < typeData.length; v++){
//依次创建数组
squares[v] = new Array();
squares[v] = that.dataObj['data'+(v+1)]
}
//左侧name的展示
yData = sumArr(squares)
var max=Math.max.apply(null, yData); //最大值
yData.forEach(item=>{
maxData.push(max) //最大值组成的数组
})
var img1 = that.numberImg[0];
var img2=that.numberImg[1]
var img3=that.numberImg[2]
//组织展示series
function creatArr(squares){
var seriesArr = []
let serOne = {
show: true,
type: 'bar',
xAxisIndex: 1, //代表使用第二个X轴刻度!!!!!!!!!!!!!!!!!!!!!!!!
barGap: '-100%',
barWidth: that.barWidth,
z: 1,
itemStyle: {
normal: {
// barBorderRadius: 200,
color: that.bgBar,
barBorderRadius: that.barBorderRadius,
},
},
tooltip:{
show:false
},
data: maxData,
label: {
normal: {
show: true,
//label 的position位置可以是top bottom left,right,也可以是固定值
fontSize:12,
//在这里需要上下统一对齐,所以用固定值
position: [0, '-300%'],
rich: { //富文本
white: { //自定义颜色
color: '#D1E4FF',
width: -17,
height: 20,
align:'right',
padding:[4,0,0,0],
},
name:{
color: '#AEC3DC',
// width: 80,
height: 20,
align:'center',
padding:[4,5,0,35],
},
nameNormal:{
color: '#AEC3DC',
// width: 80,
height: 20,
align:'center',
},
start1: {
backgroundColor: {
image: img1,
},
width: 40,
height: 18,
},
start2: {
backgroundColor: {
image: img2,
},
width: 40,
height: 18,
},
start3: {
backgroundColor: {
image: img3,
},
width: 40,
height: 20,
},
start4: {
width: 40,
height: 18,
},
},
formatter: function(data) {
var indexA = 0
leftData.forEach((item,index)=>{
if(item == data.name){
indexA = index
}
})
if(!that.isShowNumber){
return '{nameNormal|' + data.name + '}';
}else{
if(indexA == 0){
return '{start1|}{white|TOP' +[indexA+1] + ' ' +'}{name|' + data.name + '}';
}else if(indexA == 1){
return '{start2|}{white|TOP' + [indexA+1] + ' ' +'}{name|' + data.name + '}';
}else if(indexA == 2){
return '{start3|}{white|TOP' + [indexA+1] + ' ' +'}{name|' + data.name + '}';
}else{
return '{start4|}{white|TOP' + [indexA+1]+ ' ' +'}{name|' + data.name + '}';
}
}
},
}
}
}
for(var i = 0;i<squares.length;i++){
let item = {
name: typeData[i],
type: 'bar',
stack: '总量',
barWidth: that.barWidth,
data: squares[i],
z: 2,
itemStyle: {
barBorderRadius: that.barBorderRadius,
color: function(params){
if(!that.isJian){
//非渐变情况下的颜色赋值
if(that.isSingleColor&&typeData.length==1){
return that.colors[params.dataIndex]
}else{
return that.colors[params.componentIndex]
}
}else{
//渐变颜色下的赋值
if(that.isSingleColor&&typeData.length==1){
return new that.$echarts.graphic.LinearGradient(0, 0, 1, 0, [{
offset: 0,
color: that.colorsJian[params.dataIndex][0]// 0% 处的颜色
}, {
offset: 1,
color: that.colorsJian[params.dataIndex][1] // 100% 处的颜色
}], false)
}else{
return new that.$echarts.graphic.LinearGradient(0, 0, 1, 0, [{
offset: 0,
color: that.colorsJian[params.componentIndex][0]// 0% 处的颜色
}, {
offset: 1,
color: that.colorsJian[params.componentIndex][1] // 100% 处的颜色
}], false)
}
}
},
},
}
seriesArr.push(item)
}
seriesArr.push(serOne)
return seriesArr
}
that.surveyInit = that.$echarts.init(document.getElementById(this.histogramId));
let option = {
// color: that.colors,
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'none',
},
},
grid: {
top: that.grid.top,
left: that.grid.left,
right: that.grid.right,
bottom: that.grid.bottom,
containLabel: false,
},
xAxis: [
{
axisTick:{
show:that.xAxis.axisTickShow,
},
axisLine: {
show:that.xAxis.axisLineShow,
lineStyle: {
color: that.xAxis.axisLineColor
}
},
axisLabel: {
show: false, //让Y轴数据不显示
},
splitLine:{
show:that.xAxis.splitLineShow,
lineStyle: {
color: that.xAxis.splitLineColor,
type:that.xAxis.splitLineType
}
},
},
//由于下边X轴已经是百分比刻度了,所以需要在顶部加一个X轴,刻度是金额,也隐藏掉
{
show: false,
}
],
yAxis: [
{
type: 'category',
inverse: true, //是否是反向坐标轴
axisTick:{
show:that.yAxis.axisTickShow,
},
axisLine: {
show:that.yAxis.axisLineShow,
lineStyle: {
color: that.yAxis.axisLineColor
}
},
axisLabel: {
show: false, //让Y轴数据不显示
},
splitLine:{
show:that.yAxis.splitLineShow,
lineStyle: {
color: that.yAxis.splitLineColor,
type:that.yAxis.splitLineType
}
},
data: leftData
},
{
type: 'category',
inverse: true,
// inside: true,
axisTick: 'none',
axisLine: 'none',
// show:that.yAxis.axisLabelShow,
show:true,
data: yData,
axisLabel: {
interval: 0,
color:that.yAxis.axisLabelColor,
align: 'right',
verticalAlign: 'bottom',
lineHeight: that.yAxis.axisLabelLineHeight,
fontSize: that.yAxis.axisLabelSize,
padding:that.yAxis.axisLabelPadding,
formatter: function (value, i) {
return value;
},
}
},
],
// 滑动条
dataZoom: [
{
// realtime : true,
yAxisIndex: [0, 1], // 这里是从X轴的0刻度开始
show: false, // 是否显示滑动条,不影响使用
type: 'slider', // 这个 dataZoom 组件是slider型
startValue: 0, // 从头开始
endValue: that.showNum, // 一次性展示个数
},
],
series:creatArr(squares)
};
that.surveyInit.setOption(option);
setInterval(function() {
// 通过动态改变数据实现不停循环播放
let y1 = option.yAxis[0].data,
y2 = option.yAxis[1].data;
y1.push(y1.shift());
y2.push(y2.shift());
var newArr = new Array()
for(var i = 0;i<option.series.length;i++){
newArr[i] = option.series[i].data
newArr[i].push(newArr[i].shift())
}
if(that.isSingleColor&&typeData.length==1){
that.colors.push(that.colors.shift())
that.colorsJian.push(that.colorsJian.shift())
}
that.surveyInit.setOption(option);
}, 3000);
},
},
watch:{
width:function(){
this.surveyInit.resize()
},
},
mounted(){
// 新建一个promise对象
let newPromise = new Promise((resolve) => {
resolve()
})
//然后异步执行echarts的初始化函数
newPromise.then(() => {
// 此dom为echarts图标展示dom
this.initMoreColorZhu()
})
},
}
</script>