From 1e5dc53615446a620d4d0fc0068c09989686e015 Mon Sep 17 00:00:00 2001 From: yangfeng <wanwan926_4@163.com> Date: 星期一, 04 十二月 2023 18:52:11 +0800 Subject: [PATCH] 设置柱状图自动滚动 --- src/views/cockpitPage/components/MaterialChart.vue | 326 ++++++++++++++++++++++++++++-------------------------- 1 files changed, 169 insertions(+), 157 deletions(-) diff --git a/src/views/cockpitPage/components/MaterialChart.vue b/src/views/cockpitPage/components/MaterialChart.vue index 56c5eaf..ec8e420 100644 --- a/src/views/cockpitPage/components/MaterialChart.vue +++ b/src/views/cockpitPage/components/MaterialChart.vue @@ -10,7 +10,7 @@ <script> import ChartTitle from "@/views/cockpitPage/components/ChartTitle.vue"; //寮曞叆echart -import * as echarts from 'echarts' +import * as echarts from "echarts"; export default { components: { ChartTitle, @@ -18,183 +18,195 @@ props: {}, data() { return { - chartData:{ - datax:['浜у搧1', '浜у搧2', '浜у搧3', '浜у搧4','浜у搧5', '浜у搧6'], - datay:[120, 200, 150, 380, 470, 150, 230], - } + chartData: { + datax: [ + "浜у搧1", + "浜у搧2", + "浜у搧3", + "浜у搧4", + "浜у搧5", + "浜у搧6", + "浜у搧7", + "浜у搧8", + "浜у搧9", + "浜у搧10", + ], + datay: [120, 200, 150, 380, 470, 150, 230, 130, 210, 145, 330], + }, }; }, mounted() { - this.pieChart('chart',this.chartData) + this.pieChart("chart", this.chartData); }, watch: {}, methods: { //鍦ㄨ亴 - pieChart(chartName,data){ - let chartDom = this.$refs[chartName] - let myChart = echarts.init(chartDom); - let option; - let lineColor='#35ddc74d' - if(data){ - option = { - color:['#00FFFF','#dcb018'], - tooltip: { - trigger: 'axis', - axisPointer: { - type: 'none' + pieChart(chartName, data) { + let that = this; + let chartDom = this.$refs[chartName]; + let myChart = echarts.init(chartDom); + let option; + let lineColor = "#35ddc74d"; + if (data) { + option = { + color: ["#00FFFF", "#dcb018"], + tooltip: { + trigger: "axis", + axisPointer: { + type: "none", + }, + }, + grid: { + right: "80px", + bottom: "60px", + left: "60px", + top: "30px", + }, + dataZoom: [ + { + type: "inside", + yAxisIndex: 0, + show: false, + startValue: 0, // 浠庡ご寮�濮� + endValue: 5, // 涓�娆℃�у睍绀哄嚑涓� + }, + ], + legend: { + itemWidth: 8, + itemHeight: 8, + itemGap: 35, //闂磋窛 + bottom: "5px", + left: "center", + }, + yAxis: [ + { + type: "category", + axisTick: { + show: false, + }, + axisLine: { + show: true, + lineStyle: { + color: lineColor, }, }, - grid: { - right: "80px", - bottom:'60px', - left:'60px', - top:'30px', + axisLabel: { + // rotate:45, + margin: 10, + show: true, + textStyle: { + color: function (params, index) { + let colorList = ["#dcb018", "#00FFFF"]; + if (index % 2 == 0) { + return colorList[0]; + } else { + return colorList[1]; + } + }, + }, }, - dataZoom: [ - { - type: 'inside', - // show: true, //鏄剧ず婊氬姩鏉� - start:0, - end: 100, - yAxisIndex: 0, - minSpan:20, - maxSpan:100, - // handleSize: 8 + data: data.datax ? data.datax : [], + }, + ], + xAxis: [ + { + 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: + (Math.ceil(eval(`Math.max(${data.datay})`) / 7) * 7) / 7, + position: "left", + axisLine: { + show: true, + lineStyle: { + color: "#0a112B", }, - { - // type: 'slider', //涓や釜涓�涓槸slider锛屼竴涓槸inside锛宻lider鏄鍔犳粴鍔ㄦ潯浠ュ強榧犳爣鎷栧姩婊氬姩鏉″姛鑳斤紝inside鍒欐槸榧犳爣婊氳疆婊氬姩婊氬姩鏉°�� - type: 'inside', - // show: true, - // realtime : true, - yAxisIndex: 0, - minSpan:20, - maxSpan:100, - start: 0, - end: 100 - }, - ], - legend: { - itemWidth: 8, - itemHeight: 8, - itemGap: 35,//闂磋窛 - bottom:'5px', - left:'center', }, - yAxis: [ - { - type: 'category', - axisTick: { - show: false - }, - axisLine: { - show: true, - lineStyle: { - color:lineColor, - } - }, - axisLabel:{ - // rotate:45, - margin: 10, - show: true, - textStyle: { - color:function(params,index){ - let colorList=['#dcb018','#00FFFF'] - if(index % 2 == 0){ - return colorList[0] - }else{ - return colorList[1] - } - } - }, - }, - data: data.datax?data.datax:[], - } - ], - xAxis: [ - { - type: '', - name: '鍗曚綅锛氫欢', - // min: data.yAxis[0].min?data.yAxis.min:0, - minInterval: 1,//鍧愭爣杞存槸鏁存暟 - max:Math.ceil(eval(`Math.max(${data.datay})`)/5)*5,//鏁版嵁鏈�澶у�煎姞3 - interval: Math.ceil(eval( `Math.max(${data.datay})`)/7)*7 / 7, - position: 'left', - axisLine: { - show: true, - lineStyle: { - color:'#0a112B', - } - }, - nameTextStyle:{ - color:"#00FFFF", - }, - splitLine: { - show: true, - lineStyle: { - // 浣跨敤娣辨祬鐨勯棿闅旇壊 - color: lineColor, - } - }, - axisTick: { - show: false - }, - - axisLabel: { - textStyle: { - color: '#00FFFF' - }, - - } + nameTextStyle: { + color: "#00FFFF", + }, + splitLine: { + show: true, + lineStyle: { + // 浣跨敤娣辨祬鐨勯棿闅旇壊 + color: lineColor, }, - ], - series:[ - { - type: 'bar', - name: '', - barWidth: '15', - itemStyle: { - normal: { - //鏌卞舰鍥惧渾瑙掞紝鍒濆鍖栨晥鏋� - barBorderRadius:[4, 4, 0, 0], - color:function(params){ - let colorList=['#dcb018','#00FFFF'] - if(params.dataIndex % 2 == 0){ - return colorList[0] - }else{ - return colorList[1] - } - } - }, - }, - data: data.datay, - }, - ] - }; + }, + axisTick: { + show: false, + }, - option && myChart.setOption(option); - }else{ - option={}; - myChart.setOption(option,true); + axisLabel: { + textStyle: { + color: "#00FFFF", + }, + }, + }, + ], + series: [ + { + type: "bar", + name: "", + barWidth: "15", + itemStyle: { + normal: { + //鏌卞舰鍥惧渾瑙掞紝鍒濆鍖栨晥鏋� + barBorderRadius: [4, 4, 0, 0], + color: function (params) { + let colorList = ["#dcb018", "#00FFFF"]; + if (params.dataIndex % 2 == 0) { + return colorList[0]; + } else { + return colorList[1]; + } + }, + }, + }, + data: data.datay, + }, + ], + }; + setInterval(function () { + // 姣忔鍚戝乏婊戝姩涓�涓紝鏈�鍚庝竴涓粠澶村紑濮嬨�� + if (option.dataZoom[0].endValue == that.chartData.datay.length) { + option.dataZoom[0].startValue = 0; + option.dataZoom[0].endValue = 5; + } else { + option.dataZoom[0].endValue = option.dataZoom[0].endValue + 1; + option.dataZoom[0].startValue = option.dataZoom[0].startValue + 1; } - }, + myChart.setOption(option); + }, 4000); + + option && myChart.setOption(option); + window.addEventListener("resize", function () { + myChart.resize(); + }); + } else { + option = {}; + myChart.setOption(option, true); + } + }, }, }; </script> <style scoped lang="scss"> -.bar-chart{ - width:100%; - height:calc(100% - 20px); - padding:20px 0 0; - .bar-contents{ - width:100%; - height:calc(100% - 60px); - border:1px solid #00FFFF; +.bar-chart { + width: 100%; + height: calc(100% - 20px); + padding: 20px 0 0; + .bar-contents { + width: 100%; + height: calc(100% - 60px); + border: 1px solid #00ffff; box-sizing: border-box; - .chart{ - width: 100%; - height:100%; - } + .chart { + width: 100%; + height: 100%; + } } } </style> -- Gitblit v1.8.0