Bläddra i källkod

echarts引入

jinqian 3 år sedan
förälder
incheckning
658e4ec9a8
4 ändrade filer med 93 tillägg och 2 borttagningar
  1. 31 0
      package-lock.json
  2. 1 0
      package.json
  3. 7 2
      src/main.js
  4. 54 0
      src/views/system/index/page.vue

+ 31 - 0
package-lock.json

@@ -5987,6 +5987,22 @@
5987 5987
         "safer-buffer": "^2.1.0"
5988 5988
       }
5989 5989
     },
5990
+    "echarts": {
5991
+      "version": "5.2.1",
5992
+      "resolved": "https://registry.npmjs.org/echarts/-/echarts-5.2.1.tgz",
5993
+      "integrity": "sha512-OJ79b22eqRfbSV8vYmDKmA+XWfNbr0Uk/OafWcFNIGDWti2Uw9A6eVCiJLmqPa9Sk+EWL+t5v26aak0z3gxiZw==",
5994
+      "requires": {
5995
+        "tslib": "2.3.0",
5996
+        "zrender": "5.2.1"
5997
+      },
5998
+      "dependencies": {
5999
+        "tslib": {
6000
+          "version": "2.3.0",
6001
+          "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz",
6002
+          "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg=="
6003
+        }
6004
+      }
6005
+    },
5990 6006
     "editorconfig": {
5991 6007
       "version": "0.15.3",
5992 6008
       "resolved": "https://registry.npmjs.org/editorconfig/-/editorconfig-0.15.3.tgz",
@@ -15914,6 +15930,21 @@
15914 15930
           "dev": true
15915 15931
         }
15916 15932
       }
15933
+    },
15934
+    "zrender": {
15935
+      "version": "5.2.1",
15936
+      "resolved": "https://registry.npmjs.org/zrender/-/zrender-5.2.1.tgz",
15937
+      "integrity": "sha512-M3bPGZuyLTNBC6LiNKXJwSCtglMp8XUEqEBG+2MdICDI3d1s500Y4P0CzldQGsqpRVB7fkvf3BKQQRxsEaTlsw==",
15938
+      "requires": {
15939
+        "tslib": "2.3.0"
15940
+      },
15941
+      "dependencies": {
15942
+        "tslib": {
15943
+          "version": "2.3.0",
15944
+          "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz",
15945
+          "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg=="
15946
+        }
15947
+      }
15917 15948
     }
15918 15949
   }
15919 15950
 }

+ 1 - 0
package.json

@@ -16,6 +16,7 @@
16 16
     "better-scroll": "^1.15.2",
17 17
     "core-js": "^3.4.3",
18 18
     "dayjs": "^1.8.17",
19
+    "echarts": "^5.2.1",
19 20
     "element-ui": "^2.15.6",
20 21
     "faker": "^4.1.0",
21 22
     "flex.css": "^1.1.7",

+ 7 - 2
src/main.js

@@ -12,15 +12,20 @@ import router from './router'
12 12
 import { menuHeader, menuAside } from '@/menu'
13 13
 import { frameInRoutes } from '@/router/routes'
14 14
 
15
+//echarts
16
+import * as echarts from "echarts"
17
+Vue.prototype.$echarts = echarts
18
+
15 19
 // 核心插件
16 20
 Vue.use(d2Admin)
17 21
 
22
+
18 23
 new Vue({
19 24
   router,
20 25
   store,
21 26
   i18n,
22 27
   render: h => h(App),
23
-  created () {
28
+  created() {
24 29
     // 处理路由 得到每一级的路由设置
25 30
     this.$store.commit('d2admin/page/init', frameInRoutes)
26 31
     // 设置顶栏菜单
@@ -30,7 +35,7 @@ new Vue({
30 35
     // 初始化菜单搜索功能
31 36
     this.$store.commit('d2admin/search/init', menuHeader)
32 37
   },
33
-  mounted () {
38
+  mounted() {
34 39
     // 展示系统信息
35 40
     this.$store.commit('d2admin/releases/versionShow')
36 41
     // 用户登录后从数据库加载一系列的设置

+ 54 - 0
src/views/system/index/page.vue

@@ -49,6 +49,7 @@
49 49
     <el-row class="content contentX">
50 50
       <div class="page-content left-content">
51 51
         <span class="content-title">出入库数量趋势</span>
52
+        <div id="myChart" :style="{ width: '400px', height: '250px' }"></div>
52 53
       </div>
53 54
       <div class="page-content right-content">
54 55
         <span class="content-title">库区报警排名</span>
@@ -74,8 +75,58 @@ export default {
74 75
         return "two-row";
75 76
       }
76 77
     },
78
+    drawLine() {
79
+      // 基于准备好的dom,初始化echarts实例
80
+      let myChart = this.$echarts.init(document.getElementById("myChart"));
81
+      // 绘制图表
82
+      myChart.setOption({
83
+        // title: { text: "在Vue中使用echarts" },
84
+        tooltip: {},
85
+        legend: {
86
+          data: ["出库", "入库"],
87
+        },
88
+        xAxis: {
89
+          type: "category",
90
+          boundaryGap: false,
91
+          data: [
92
+            "1月",
93
+            "2月",
94
+            "3月",
95
+            "4月",
96
+            "5月",
97
+            "6月",
98
+            "7月",
99
+            "8月",
100
+            "9月",
101
+            "10月",
102
+            "11月",
103
+            "12月",
104
+          ],
105
+        },
106
+        yAxis: { type: "value" },
107
+        series: [
108
+          {
109
+            name: "出库",
110
+            type: "line",
111
+            stack: "Total",
112
+            smooth: true,
113
+            data: [120, 132, 101, 134, 90, 230, 210, 120, 132, 101, 134, 90],
114
+          },
115
+          {
116
+            name: "入库",
117
+            type: "line",
118
+            stack: "Total",
119
+            smooth: true,
120
+            data: [220, 182, 191, 234, 290, 330, 310, 120, 132, 101, 134, 90],
121
+          },
122
+        ],
123
+      });
124
+    },
77 125
   },
78 126
   created() {},
127
+  mounted() {
128
+    this.drawLine();
129
+  },
79 130
 };
80 131
 </script>
81 132
 
@@ -166,6 +217,9 @@ export default {
166 217
   .tzggListLi {
167 218
     float: right;
168 219
   }
220
+  #myChart {
221
+    margin: 0 auto;
222
+  }
169 223
   // .btn-group {
170 224
   //   color: $color-text-placehoder;
171 225
   //   font-size: 12px;