|
|
<template>
|
|
|
<div :class="className" :style="{ height: height, width: width }" />
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import * as echarts from "echarts";
|
|
|
require("echarts/theme/macarons"); // echarts theme
|
|
|
import resize from "./mixins/resize";
|
|
|
|
|
|
const animationDuration = 6000;
|
|
|
|
|
|
export default {
|
|
|
mixins: [resize],
|
|
|
props: {
|
|
|
className: {
|
|
|
type: String,
|
|
|
default: "chart",
|
|
|
},
|
|
|
width: {
|
|
|
type: String,
|
|
|
default: "100%",
|
|
|
},
|
|
|
height: {
|
|
|
type: String,
|
|
|
default: "250px",
|
|
|
},
|
|
|
chartData: {
|
|
|
type: Array,
|
|
|
default: [],
|
|
|
},
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
chart: null,
|
|
|
};
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
chartData: {
|
|
|
deep: true,
|
|
|
handler(newValue, oldValue) {
|
|
|
this.chart.dispose();
|
|
|
this.chartData = newValue;
|
|
|
this.initChart(); //值发生改变则渲染一次echarts
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
mounted() {
|
|
|
this.$nextTick(() => {
|
|
|
this.initChart();
|
|
|
});
|
|
|
},
|
|
|
beforeDestroy() {
|
|
|
if (!this.chart) {
|
|
|
return;
|
|
|
}
|
|
|
this.chart.dispose();
|
|
|
this.chart = null;
|
|
|
},
|
|
|
methods: {
|
|
|
initChart() {
|
|
|
this.chart = echarts.init(this.$el, "macarons");
|
|
|
let yLabel = [];
|
|
|
let yData = [];
|
|
|
let yRtData = [];
|
|
|
if(this.chartData.length>0){
|
|
|
this.chartData.forEach((item) => {
|
|
|
yLabel.push(item.machineName)
|
|
|
yData.push(item.quantitySplit)
|
|
|
yRtData.push(item.quantitySplit)
|
|
|
});
|
|
|
}
|
|
|
this.chart.setOption({
|
|
|
grid: {
|
|
|
left: "5%",
|
|
|
right: "5%",
|
|
|
bottom: "10%",
|
|
|
top: "5%",
|
|
|
containLabel: true,
|
|
|
},
|
|
|
tooltip: {
|
|
|
show: true,
|
|
|
trigger: "axis", //axis , item
|
|
|
backgroundColor: "RGBA(0, 49, 85, 1)",
|
|
|
borderColor: "rgba(0, 151, 251, 1)",
|
|
|
borderWidth: 1,
|
|
|
borderRadius: 0,
|
|
|
axisPointer: {
|
|
|
type: "none",
|
|
|
// show:false
|
|
|
},
|
|
|
textStyle: {
|
|
|
color: "#BCE9FC",
|
|
|
fontSize: 16,
|
|
|
align: "left",
|
|
|
},
|
|
|
formatter: function (a) {
|
|
|
return a[0].seriesName + ":" + a[0].value;
|
|
|
},
|
|
|
},
|
|
|
// backgroundColor: "#031d33",
|
|
|
xAxis: {
|
|
|
// name:'箱',
|
|
|
show: true,
|
|
|
type: "value",
|
|
|
// data:xData
|
|
|
splitNumber: 7,
|
|
|
axisLabel: {
|
|
|
//坐标轴刻度标签的相关设置。
|
|
|
interval: 0, //设置为 1,表示『隔一个标签显示一个标签』
|
|
|
// margin:15,
|
|
|
textStyle: {
|
|
|
// color: "rgba(128, 207, 240, 1)",
|
|
|
fontStyle: "normal",
|
|
|
fontSize: 16,
|
|
|
// fontWeight: 'bolder'
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
yAxis: [
|
|
|
{
|
|
|
type: "category",
|
|
|
inverse: true,
|
|
|
axisLabel: {
|
|
|
show: true,
|
|
|
margin: 10,
|
|
|
textStyle: {
|
|
|
fontSize: "14",
|
|
|
fontWeight: "bolder",
|
|
|
},
|
|
|
},
|
|
|
splitLine: {
|
|
|
show: false,
|
|
|
},
|
|
|
axisTick: {
|
|
|
show: false,
|
|
|
},
|
|
|
axisLine: {
|
|
|
show: false,
|
|
|
},
|
|
|
data: yLabel,
|
|
|
},
|
|
|
{
|
|
|
type: "category",
|
|
|
inverse: true,
|
|
|
axisTick: "none",
|
|
|
axisLine: "none",
|
|
|
show: true,
|
|
|
axisLabel: {
|
|
|
textStyle: {
|
|
|
color: "rgba(128, 207, 240, 1)",
|
|
|
fontSize: "14",
|
|
|
},
|
|
|
formatter: function (value) {
|
|
|
return value;
|
|
|
},
|
|
|
},
|
|
|
data: yRtData,
|
|
|
},
|
|
|
],
|
|
|
series: [
|
|
|
{
|
|
|
name: "数量",
|
|
|
type: "bar",
|
|
|
zlevel: 1,
|
|
|
itemStyle: {
|
|
|
normal: {
|
|
|
color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
|
|
|
{
|
|
|
offset: 1,
|
|
|
color: "#0097FB",
|
|
|
},
|
|
|
{
|
|
|
offset: 0,
|
|
|
color: "#30ECA6",
|
|
|
},
|
|
|
]),
|
|
|
// shadowBlur: 0,
|
|
|
// shadowColor: 'rgba(87,220,222,0.7)',
|
|
|
},
|
|
|
},
|
|
|
barWidth: 18,
|
|
|
data: yData,
|
|
|
},
|
|
|
],
|
|
|
});
|
|
|
},
|
|
|
},
|
|
|
};
|
|
|
</script>
|