barsChart.vue
2.99 KB
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
<template>
<div>
<basic ref="basic" :chartId="chartId" :chartData="chartData"></basic>
</div>
</template>
<script>
import mixin from "./mixin";
export default {
mixins: [mixin],
data() {
return {};
},
methods: {
/**
* 预处理option参数
* */
preChartData(cdata) {
return cdata;
},
/**
* 处理option参数
* */
dealChartData(optionFormat) {
// 特殊配置项
let {
grid,
_color,
hasYaxisName,
yAxisLineHide,
legendBottom,
seriesText,
yAxisName,
tooltipTitle,
labelShow = true,
labelPosition = "",
hideLoading = false,
reverseAxis = false,
showBackground = false,
isSex = false,
total = [],
} = optionFormat.otherConf;
optionFormat.color = _color; //this.getRandomColors(optionFormat.series.length);
optionFormat.hideLoading = hideLoading;
optionFormat.animation = true;
optionFormat.grid = grid || [
{ top: 10, right: hasYaxisName ? 40 : 20, bottom: 20, left: 40 },
];
let that = this;
optionFormat.series.forEach((item, index) => {
let count = 0;
if(!isSex){
count = item.data.reduce((count,it)=>count+it,0);
}
item.showBackground = showBackground;
item.label = {
show: labelShow,
fontSize: 12,
color:'#6a696c',
//fontWeight:'bold',
position: labelPosition || "insideRight",
formatter(param){
return parseInt(param.value*100/count)+'%/'+param.value+that.$t('format.perNum');
}
};
if (isSex) {
item.itemStyle = {
color: _color[index],
};
item.label.show = true;
item.label.formatter = (param)=>{
return total[param.dataIndex][index];
}
if (index == 0) {
item.itemStyle.barBorderRadius = [20, 0, 0, 20];
item.label.position = 'left';
} else if (index == 1) {
item.itemStyle.barBorderRadius = [0, 20, 20, 0];
item.label.position = 'right';
}
}
});
if (isSex) {
optionFormat.yAxis.forEach((item, index) => {
item.axisLabel = {
color: _color[index],
formatter(label, i) {
let per = optionFormat.series[index].data[i] + "%";
return (
"{a|" + per + "}" + (index == 0 ? "{b|" + label + "}" : "")
);
},
rich: {
a: {
width: 40,
},
b: {
width: this.$el.offsetWidth * 0.3 - 100,
color: "#000",
align: "center",
},
},
};
});
}
let option = Object.assign({}, optionFormat);
return option;
},
},
created() {},
};
</script>
<style scoped>
.chart {
position: relative;
height: 500px;
}
</style>