From 9a664d3cdbcafbfe89e21440172b0cca254483ee Mon Sep 17 00:00:00 2001
From: haoxuan <haoxuan>
Date: 星期五, 01 十二月 2023 11:54:23 +0800
Subject: [PATCH] echart

---
 src/components/cockpitPage/BarChart.vue |  148 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 145 insertions(+), 3 deletions(-)

diff --git a/src/components/cockpitPage/BarChart.vue b/src/components/cockpitPage/BarChart.vue
index eb1c945..7852254 100644
--- a/src/components/cockpitPage/BarChart.vue
+++ b/src/components/cockpitPage/BarChart.vue
@@ -2,13 +2,15 @@
   <div class="bar-chart">
     <ChartTitle name="杞﹂棿姝e搧鐜�"></ChartTitle>
     <div class="bar-contents">
-
+      <div class="chart" ref="chart"></div>
     </div>
   </div>
 </template>
 
 <script>
 import ChartTitle from "@/components/cockpitPage/ChartTitle.vue";
+//寮曞叆echart
+import * as echarts from 'echarts'
 export default {
   components: {
     ChartTitle,
@@ -20,11 +22,147 @@
     };
   },
   mounted() {
-
+    let chartData={
+      datax:['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
+      datay:[120, 200, 150, 80, 70, 110, 130]
+    }
+    this.pieChart('chart',chartData)
   },
   watch: {},
   methods: {
-    
+    //鍦ㄨ亴
+    pieChart(chartName,data){
+          let chartDom = this.$refs[chartName]
+          let myChart = echarts.init(chartDom);
+          let option;
+          if(data){
+            option = {
+              color:['#618DF8'],
+              tooltip: {
+                trigger: 'axis',
+                axisPointer: {
+                  type: 'none'
+                }
+              },
+              grid: {
+                right: "11%",
+                bottom:'21%',
+              },
+              dataZoom: [
+                {
+                  type: 'inside',
+                  // show: true, //鏄剧ず婊氬姩鏉�
+                  start:0,
+                  end: 100,
+                  xAxisIndex: 0,
+                  minSpan:20,
+                  maxSpan:100,
+                  // handleSize: 8
+                },
+                {
+                  //   type: 'slider', //涓や釜涓�涓槸slider锛屼竴涓槸inside锛宻lider鏄鍔犳粴鍔ㄦ潯浠ュ強榧犳爣鎷栧姩婊氬姩鏉″姛鑳斤紝inside鍒欐槸榧犳爣婊氳疆婊氬姩婊氬姩鏉°��
+                  type: 'inside',
+                  // show: true,
+                  // realtime : true,
+                  xAxisIndex: 0,
+                  minSpan:20,
+                  maxSpan:100,
+                  start: 0,
+                  end: 100
+                },
+              ],
+              legend: {
+                itemWidth: 12,
+                itemHeight: 12,
+                itemGap: 35,//闂磋窛
+                // data:data.legend?[
+                //   {
+                //     name:data.legend.data[0],
+                //     icon: 'roundRect',
+                //   },
+                // ]:[]
+              },
+              xAxis: [
+                {
+                  type: 'category',
+                  axisTick: {
+                    show: false
+                  },
+                  axisLine: {
+                    show: true,
+                    lineStyle: {
+                      color:'#EAEAEA',
+                    }
+                  },
+                  axisLabel:{
+                    rotate:45,
+                    margin: 12,
+                    show: true,
+                    textStyle: {
+                      color: '#9B9B9B'
+                    },
+                  },
+                  data: data.datax?data.datax:[],
+                }
+              ],
+              yAxis: [
+                {
+                  type: '',
+                  name: 'yyy',
+                  // 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})`)/5)*5 / 5,
+                  position: 'left',
+                  axisLine: {
+                    show: true,
+                    lineStyle: {
+                      color:'#EAEAEA',
+                    }
+                  },
+                  nameTextStyle:{
+                    color:"#9B9B9B",
+                  },
+                  splitLine: {
+                    show: true,
+                    lineStyle: {
+                      // 浣跨敤娣辨祬鐨勯棿闅旇壊
+                      color: '#EAEAEA',
+                    }
+                  },
+                  axisTick: {
+                    show: false
+                  },
+                  axisLabel: {
+                    textStyle: {
+                      color: '#9B9B9B'
+                    },
+                    formatter: ''
+                  }
+                }
+              ],
+              series:[
+                {
+                  type: '',
+                  name: 'y',
+                  barWidth: '20%',
+                  itemStyle: {
+                    normal: {
+                      //鏌卞舰鍥惧渾瑙掞紝鍒濆鍖栨晥鏋�
+                      barBorderRadius:[4, 4, 0, 0],
+                    }
+                  },
+                  data: data.datay,
+                }
+              ]
+            };
+
+            option && myChart.setOption(option);
+          }else{
+            option={};
+            myChart.setOption(option,true);
+          }
+        },
   },
 };
 </script>
@@ -39,6 +177,10 @@
     height:calc(100% - 60px);
     border:1px solid #00FFFF;
     box-sizing: border-box;
+    .chart{
+        width: 100%;
+        height:100%;
+      }
   }
 }
 </style>

--
Gitblit v1.8.0