From de30afc054a9f72b49d2b81d4c7d6891a5e97e12 Mon Sep 17 00:00:00 2001 From: yangfeng <wanwan926_4@163.com> Date: 星期五, 08 十二月 2023 11:07:57 +0800 Subject: [PATCH] 车间正品率优化 --- src/views/cockpitPage/components/DeviceChart.vue | 111 +++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 79 insertions(+), 32 deletions(-) diff --git a/src/views/cockpitPage/components/DeviceChart.vue b/src/views/cockpitPage/components/DeviceChart.vue index ec25403..7479b4a 100644 --- a/src/views/cockpitPage/components/DeviceChart.vue +++ b/src/views/cockpitPage/components/DeviceChart.vue @@ -15,39 +15,49 @@ <script> //寮曞叆echart import * as echarts from "echarts"; +let myChart; export default { components: {}, - props: {}, + props: { + chartData: { + type: Object, + require: true, + default: () => { + return { + datax: [], + datay: [], + }; + }, + }, + }, data() { return { - chartData: { - datax: [ - "璁惧1", - "璁惧2", - "璁惧3", - "璁惧4", - "璁惧5", - "璁惧6", - "璁惧7", - "璁惧8", - "璁惧9", - ], - datay: [10, 20, 15, 38, 47, 50, 20, 33, 25, 48], - }, + startValue: 0, + endValue: 5, + chartTimer: null, }; }, - mounted() { - this.pieChart("chart", this.chartData); + watch: { + "chartData.datay"(val) { + this.startValue = 0; + this.endValue = 5; + this.pieChart("chart", this.chartData); + }, }, - watch: {}, + mounted() {}, methods: { //鍦ㄨ亴 pieChart(chartName, data) { let that = this; + clearInterval(this.chartTimer); let chartDom = this.$refs[chartName]; - let myChart = echarts.init(chartDom); + if (myChart != null && myChart != "" && myChart != undefined) { + myChart.dispose(); //閿�姣� + } + myChart = echarts.init(chartDom); let option; let lineColor = "#35ddc74d"; + let spirit = "/cockpitPage/order-bg.png"; if (data) { option = { color: ["#00FFFF", "#dcb018"], @@ -56,11 +66,19 @@ axisPointer: { type: "none", }, + textStyle: { + color: "#00FFFF", + }, + borderColor: "#00FFFF", + backgroundColor: "#238d8d6b", + valueFormatter: function (value) { + return value + "%"; + }, }, grid: { right: "80px", bottom: "60px", - left: "60px", + left: "70px", top: "30px", }, dataZoom: [ @@ -68,8 +86,11 @@ type: "inside", yAxisIndex: 0, show: false, - startValue: 0, // 浠庡ご寮�濮� - endValue: 5, // 涓�娆℃�у睍绀哄嚑涓� + startValue: that.startValue, // 浠庡ご寮�濮� + endValue: that.endValue, // 涓�娆℃�у睍绀哄嚑涓� + zoomOnMouseWheel: false, + moveOnMouseWheel: true, + moveOnMouseMove: true, }, ], legend: { @@ -95,6 +116,7 @@ // rotate:45, margin: 10, show: true, + fontSize: 12, textStyle: { color: function (params, index) { let colorList = ["#dcb018", "#00FFFF"]; @@ -104,6 +126,12 @@ return colorList[1]; } }, + }, + formatter: function (value) { + if (value.length > 5) { + return `${value.slice(0, 4)}...`; + } + return value; }, }, data: data.datax ? data.datax : [], @@ -138,24 +166,44 @@ axisTick: { show: false, }, - axisLabel: { textStyle: { color: "#00FFFF", }, - formatter: "{value}%", + formatter: function (value) { + return `${value}%`; + }, }, }, ], series: [ { - type: "bar", + type: "pictorialBar", name: "", - barWidth: "15", + symbol: spirit, + symbolRepeat: true, + symbolMargin: "25%", + symbolClip: true, + symbolSize: [4, 11], + barCategoryGap: "40%", label: { show: true, position: "right", - color: "#00FFFF", + formatter: function (params) { + if (params.dataIndex % 2 == 0) { + return `{a|${params.value}%}`; + } else { + return `{b|${params.value}%}`; + } + }, + rich: { + a: { + color: "#00FFFF", + }, + b: { + color: "#dcb018", + }, + }, }, itemStyle: { normal: { @@ -176,11 +224,10 @@ ], }; - setInterval(function () { - // 姣忔鍚戝乏婊戝姩涓�涓紝鏈�鍚庝竴涓粠澶村紑濮嬨�� - if (option.dataZoom[0].endValue == that.chartData.datay.length) { - option.dataZoom[0].startValue = 0; - option.dataZoom[0].endValue = 5; + this.chartTimer = setInterval(function () { + if (option.dataZoom[0].endValue == data.datay.length) { + option.dataZoom[0].startValue = that.startValue; + option.dataZoom[0].endValue = that.endValue; } else { option.dataZoom[0].endValue = option.dataZoom[0].endValue + 1; option.dataZoom[0].startValue = option.dataZoom[0].startValue + 1; -- Gitblit v1.8.0