From 1dbdda3517a01851d8d9894b22e61aa4462b541c Mon Sep 17 00:00:00 2001 From: yangfeng <wanwan926_4@163.com> Date: 星期四, 07 十二月 2023 19:16:36 +0800 Subject: [PATCH] tooltip值优化 --- src/views/cockpitPage/components/DeviceChart.vue | 72 +++++++++++++++++++---------------- 1 files changed, 39 insertions(+), 33 deletions(-) diff --git a/src/views/cockpitPage/components/DeviceChart.vue b/src/views/cockpitPage/components/DeviceChart.vue index 1e8f376..a88e6be 100644 --- a/src/views/cockpitPage/components/DeviceChart.vue +++ b/src/views/cockpitPage/components/DeviceChart.vue @@ -29,57 +29,35 @@ }; }, }, - // xdata: { - // type: Array, - // require: true, - // }, - // ydata: { - // type: Array, - // require: true, - // }, }, data() { return { - // chartData: { - // datax: [], - // datay: [], - // }, startValue: 0, endValue: 5, - chartTimer:null, + chartTimer: null, }; }, watch: { "chartData.datay"(val) { - console.log(val, "璁惧鍙樻洿鏁版嵁"); - this.ydata = val; this.startValue = 0; this.endValue = 5; this.pieChart("chart", this.chartData); }, }, - mounted() { - // this.pieChart("chart", this.chartData); - }, + mounted() {}, methods: { //鍦ㄨ亴 pieChart(chartName, data) { let that = this; clearInterval(this.chartTimer); - let chartDomTwo = this.$refs[chartName]; - let myChartTwo = echarts.init(chartDomTwo) - myChartTwo.dispose() let chartDom = this.$refs[chartName]; + if (myChart != null && myChart != "" && myChart != undefined) { + myChart.dispose(); //閿�姣� + } myChart = echarts.init(chartDom); - // if (myChart != null && myChart != "" && myChart != undefined) { - // console.log("222222222"); - // myChart.dispose(); //閿�姣� - // myChart.resize(); - // } - // console.log(myChart, "ssssssss"); let option; let lineColor = "#35ddc74d"; - if (this.ydata) { + if (data) { option = { color: ["#00FFFF", "#dcb018"], tooltip: { @@ -87,11 +65,14 @@ axisPointer: { type: "none", }, + valueFormatter: function (value) { + return value + "%"; + }, }, grid: { right: "80px", bottom: "60px", - left: "60px", + left: "70px", top: "30px", }, dataZoom: [ @@ -101,6 +82,9 @@ show: false, startValue: that.startValue, // 浠庡ご寮�濮� endValue: that.endValue, // 涓�娆℃�у睍绀哄嚑涓� + zoomOnMouseWheel: false, + moveOnMouseWheel: true, + moveOnMouseMove: true, }, ], legend: { @@ -126,6 +110,7 @@ // rotate:45, margin: 10, show: true, + fontSize: 12, textStyle: { color: function (params, index) { let colorList = ["#dcb018", "#00FFFF"]; @@ -135,6 +120,12 @@ return colorList[1]; } }, + }, + formatter: function (value) { + if (value.length > 5) { + return `${value.slice(0, 4)}...`; + } + return value; }, }, data: data.datax ? data.datax : [], @@ -169,12 +160,13 @@ axisTick: { show: false, }, - axisLabel: { textStyle: { color: "#00FFFF", }, - formatter: "{value}%", + formatter: function (value) { + return `${value}%`; + }, }, }, ], @@ -186,7 +178,21 @@ 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: { @@ -207,7 +213,7 @@ ], }; - this.chartTimer=setInterval(function () { + this.chartTimer = setInterval(function () { if (option.dataZoom[0].endValue == data.datay.length) { option.dataZoom[0].startValue = that.startValue; option.dataZoom[0].endValue = that.endValue; -- Gitblit v1.8.0