
<template>
<div
:class="className"
:style="{ height: height, width: width, 'min-height': minHeight }"
/>
template>
<script>
import echarts from "echarts";
import { debounce } from "@/utils";
require("echarts/theme/macarons");
import "echarts-liquidfill";
const animationDuration = 6000;
export default {
props: {
className: {
type: String,
default: "chart",
},
width: {
type: String,
default: "100%",
},
height: {
type: String,
default: "10rem",
},
minHeight: {
type: String,
default: "5rem",
},
param: {
type: Array,
default: () => {},
},
},
data() {
return {
chart: null,
};
},
watch: {
param: {
handler: function (value) {
this.$nextTick((_) => {
this.initChart();
});
},
immediate: true,
},
},
mounted() {
this.$nextTick(() => {
this.initChart();
});
this.__resizeHandler = debounce(() => {
if (this.chart) {
this.chart.resize();
}
}, 100);
window.addEventListener("resize", this.__resizeHandler);
},
beforeDestroy() {
if (!this.chart) {
return;
}
window.removeEventListener("resize", this.__resizeHandler);
this.chart.dispose();
this.chart = null;
},
methods: {
initChart() {
let color = this.$store.state.color.colorListPars;
this.chart = echarts.init(this.$el, "macarons");
let dataName = [];
let dataNum = [];
let completeNum = [];
let scatteredNum = [];
this.param.map((item) => {
dataName.push(item.staffName);
dataNum.push(parseFloat(Number(item.num).toFixed(0)));
completeNum.push(parseFloat(Number(item.completeNum).toFixed(0)));
scatteredNum.push(parseFloat(Number(item.scatteredNum).toFixed(0)));
});
let option = {
color: ["#2394ef"],
grid: {
left: "1px",
bottom: "0px",
top: "10px",
containLabel: true,
},
xAxis: {
type: "category",
axisLine: { lineStyle: { color: "#EFEFEF" } },
axisLabel: {
textStyle: {
color: color,
fontSize: 12,
},
formatter: function (value) {
return value.split("").join("\n");
},
},
data: dataName,
},
legend: {
orient: "vertical",
top: 0,
right: 0,
itemWidth: 10,
itemHeight: 10,
icon: "circle",
data: ["整件", "零散"],
},
tooltip: {
trigger: "axis",
axisPointer: {
type: "shadow",
},
formatter: function (params, ticket, callback) {
return (
"总数量:" +
parseFloat(Number(params[0].data + params[1].data).toFixed(0)) +
"件
整件:" +
parseFloat(Number(params[0].data).toFixed(0)) +
"件
零散:" +
parseFloat(Number(params[1].data).toFixed(0)) +
"件"
);
},
},
yAxis: {
axisLabel: {
color: color,
formatter: "{value}件",
},
axisLine: { show: true, lineStyle: { color: "#FFFFFF" } },
},
series: [
{
name: "整件",
type: "bar",
stack: "total",
barWidth: 24,
color: "#2D8EFF",
itemStyle: { borderRadius: 0 },
data: completeNum,
},
{
name: "零散",
type: "bar",
stack: "total",
barWidth: 24,
color: "#CAE1FF",
itemStyle: { borderRadius: [12, 12, 0, 0] },
data: scatteredNum,
},
{
data: dataNum,
type: "line",
emphasis: {
focus: "series",
},
barWidth: 1,
lineStyle: {
color: "transparent",
},
symbol: "none",
markLine: {
data: [
{
type: "average",
name: "平均值",
},
],
},
},
],
};
if (this.param.length > 20) {
option.dataZoom = [
{
type: "slider",
show: true,
xAxisIndex: [0],
start: 0,
end: 20,
textStyle: {
color: "#ccd7d7",
},
filterMode: "empty",
bottom: 14,
},
];
}
if (option && typeof option == "object") {
this.chart.setOption(option);
}
},
},
};
script>

- 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