From 93d04e35d6ff02470687b73ff7494b62bdc85f2c Mon Sep 17 00:00:00 2001 From: yangfeng <wanwan926_4@163.com> Date: 星期三, 06 十二月 2023 16:32:38 +0800 Subject: [PATCH] 页面背景图及饼图显示优化 --- src/views/cockpitPage/components/BarChart.vue | 93 ++++++++++++++++++++++++++++++++-------------- 1 files changed, 64 insertions(+), 29 deletions(-) diff --git a/src/views/cockpitPage/components/BarChart.vue b/src/views/cockpitPage/components/BarChart.vue index 3ca2077..15e3d29 100644 --- a/src/views/cockpitPage/components/BarChart.vue +++ b/src/views/cockpitPage/components/BarChart.vue @@ -15,42 +15,70 @@ import ChartTitle from "@/views/cockpitPage/components/ChartTitle.vue"; //寮曞叆echart import * as echarts from "echarts"; +let myChart; export default { components: { ChartTitle, }, - props: {}, + props: { + chartData: { + type: Object, + require: true, + default: () => { + return { + total: 0, + rate: "0", + datax: [], + datay: [], + datay2: [], + }; + }, + }, + }, data() { return { - chartData: { - total: 1000, - rate: "99%", - datax: [ - "绗竴杞﹂棿", - "绗簩杞﹂棿", - "绗笁杞﹂棿", - "绗洓杞﹂棿", - "绗簲杞﹂棿", - "绗叚杞﹂棿", - "绗竷杞﹂棿", - "绗叓杞﹂棿", - "绗節杞﹂棿", - ], - datay: [120, 200, 150, 180, 170, 150, 130, 180, 140], - datay2: [20, 30, 50, 40, 70, 50, 30, 80, 40], - }, + // chartData: { + // total: 1000, + // rate: "99%", + // datax: [ + // "绗竴杞﹂棿", + // "绗簩杞﹂棿", + // "绗笁杞﹂棿", + // "绗洓杞﹂棿", + // "绗簲杞﹂棿", + // "绗叚杞﹂棿", + // "绗竷杞﹂棿", + // "绗叓杞﹂棿", + // "绗節杞﹂棿", + // ], + // datay: [120, 200, 150, 180, 170, 150, 130, 180, 140], + // datay2: [20, 30, 50, 40, 70, 50, 30, 80, 40], + // }, + 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() { + // this.pieChart("chart", this.chartData); + }, 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"; if (data) { @@ -105,8 +133,11 @@ type: "inside", xAxisIndex: 0, show: false, - startValue: 0, // 浠庡ご寮�濮� - endValue: 5, // 涓�娆℃�у睍绀哄嚑涓� + startValue: that.startValue, // 浠庡ご寮�濮� + endValue: that.endValue, // 涓�娆℃�у睍绀哄嚑涓� + zoomOnMouseWheel: false, + moveOnMouseWheel: true, + moveOnMouseMove: true, }, ], legend: { @@ -145,11 +176,16 @@ }, }, axisLabel: { - // rotate:45, margin: 10, show: true, textStyle: { color: "#00FFFF", + }, + formatter: function (value) { + if (value.length > 4) { + return `${value.slice(0, 3)}...`; + } + return value; }, }, data: data.datax ? data.datax : [], @@ -159,7 +195,6 @@ { type: "value", name: "", - // min: data.yAxis[0].min?data.yAxis.min:0, minInterval: 1, //鍧愭爣杞存槸鏁存暟 max: Math.ceil(eval(`Math.max(${data.datay})`) / 5) * 5, //鏁版嵁鏈�澶у�煎姞3 interval: @@ -254,11 +289,11 @@ }, ], }; - setInterval(function () { + this.chartTimer = setInterval(function () { // 姣忔鍚戝乏婊戝姩涓�涓紝鏈�鍚庝竴涓粠澶村紑濮嬨�� if (option.dataZoom[0].endValue == that.chartData.datay.length) { - option.dataZoom[0].startValue = 0; - option.dataZoom[0].endValue = 5; + 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