duwendi 1 anno fa
parent
commit
35bf2ca1bd

+ 4 - 1
package.json

@@ -20,7 +20,10 @@
20 20
     "vue": "^2.5.2",
21 21
     "vue-router": "^3.0.1",
22 22
     "vue-tree-color": "^2.3.2",
23
-    "vuex": "^3.6.2"
23
+    "vuex": "^3.6.2",
24
+    "echarts": "^4.9.0",
25
+    "echarts-gl": "^1.1.1",
26
+    "echarts-liquidfill": "^2.0.5"
24 27
   },
25 28
   "devDependencies": {
26 29
     "autoprefixer": "^7.1.2",

+ 187 - 0
src/components/barChart.vue

@@ -0,0 +1,187 @@
1
+<template>
2
+	<div class="chart" :id="id"></div>
3
+</template>
4
+
5
+<script>
6
+import * as echarts from 'echarts'
7
+const colors = [
8
+  new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
9
+    offset: 0,
10
+    color: '#1EBFFF'
11
+    },
12
+    {
13
+    offset: 1,
14
+    color: 'rgb(31, 96, 223)'
15
+    }
16
+  ]),
17
+  new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
18
+    offset: 0,
19
+    color: '#FFCA02'
20
+    },
21
+    {
22
+    offset: 1,
23
+    color: '#FF6E2F'
24
+    }
25
+  ])
26
+]
27
+export default {
28
+  props: {
29
+    id: {type: String, required: true},
30
+    dataset: {type: Array, required: true},
31
+    encode: {type: Array, required: true},
32
+    yAxisName: {type: Array},
33
+    xlabelFormat: {type: Function},
34
+    showLegend: {type: Boolean, default: true},
35
+    top: {type: Number, default: 50},
36
+    colorIdx: {type: Number}, // 颜色idx
37
+    colorArr: {type: Array, default: ()=>colors},
38
+    bottom: {type: Number},
39
+    legendIcon: {type: String, default: 'circle'},
40
+    tooltip: {type: Function}, // tooltip format
41
+    stack: {type: String},
42
+    isBig: {type: Boolean, default: false},
43
+    labelSize: {type: Number, default: 12},
44
+    autoStop: {type: Boolean, default: true} // tooltip循环会否循环一轮后自动停止
45
+  },
46
+  data() {
47
+    return {
48
+      option: {
49
+        grid: {
50
+          top: this.top,
51
+          bottom: this.xlabelFormat ? 50 : 30,
52
+          left: 45,
53
+          right: 45,
54
+        },
55
+        legend: {right: 0, top: 0, icon: this.legendIcon, textStyle: {color: '#000', fontSize: 12}},
56
+        tooltip: {
57
+          trigger: 'axis',
58
+          // confine: true,
59
+          // backgroundColor: 't',
60
+          // axisPointer: {
61
+          //   lineStyle: { color: "#0081AC", type: "dashed" },
62
+          // },
63
+          // show: this.tooltip,
64
+          // formatter: this.tooltip,
65
+          //  position: function(point, params, dom,rect,size) {
66
+          //    let boxWidth = size.contentSize[0];
67
+          //    let boxHeight = size.contentSize[1];
68
+          //    return [point[0]-boxWidth-20, point[1]-boxHeight-40];
69
+          //  }
70
+        },
71
+        xAxis: {
72
+          type: 'category',
73
+          axisLabel: {
74
+            interval: 0,
75
+          },
76
+           axisLine: {
77
+            lineStyle: {
78
+              // color: '#1977C6'
79
+            }
80
+          },
81
+          splitLine: {
82
+            lineStyle: {
83
+              // color: '#082E81',
84
+              type: 'dashed'
85
+            }
86
+          },
87
+          axisTick: false
88
+        },
89
+        yAxis: [{
90
+          axisLine: {
91
+            show: false
92
+          },
93
+          nameTextStyle: {
94
+            fontSize: this.labelSize
95
+          },
96
+          splitLine: {
97
+            lineStyle: {
98
+              // color: '#082E81',
99
+              type: 'dashed'
100
+            }
101
+          },
102
+          axisTick: false,
103
+        },{
104
+          axisLine: {
105
+            show: false
106
+          },
107
+          nameTextStyle: {
108
+            fontSize: this.labelSize
109
+          },
110
+          splitLine: {
111
+            lineStyle: {
112
+              // color: '#082E81',
113
+              type: 'dashed'
114
+            }
115
+          },
116
+          axisTick: false,
117
+        }],
118
+        dataset: {},
119
+        series: []
120
+      }
121
+    }
122
+  },
123
+  watch: {
124
+    dataset: function(newV) {
125
+      const option = this.option
126
+      option.dataset.source = newV
127
+      this.chart.setOption(option)
128
+    }
129
+  },
130
+  mounted() {
131
+    this.chart = echarts.init($(`#${this.id}`)[0])
132
+    const option = this.option
133
+    option.yAxis[0].name = this.yAxisName[0]
134
+    option.yAxis[1].name = this.yAxisName[1]
135
+    if (this.xlabelFormat) {
136
+      option.xAxis.axisLabel.formatter = this.xlabelFormat
137
+    }
138
+    this.encode.map((encode, idx) => {
139
+      option.series.push({
140
+        name: encode.seriesName,
141
+        type: 'bar',
142
+        stack: this.stack,
143
+        barWidth: 10,
144
+        yAxisIndex: idx,
145
+        encode: encode,
146
+        itemStyle: {
147
+          barBorderRadius: this.legendIcon === 'circle' ? [5, 5, 0, 0] : 0,
148
+          color: this.colorArr[idx]
149
+        }
150
+      })
151
+    })
152
+    option.dataset.source = this.dataset
153
+    // if (this.tooltipFormat) {
154
+    //   option.tooltip.formatter = this.tooltipFormat
155
+    // }
156
+    // option.tooltip= {
157
+    //   trigger: 'axis',
158
+    //     axisPointer: {
159
+    //     // type: 'shadow'
160
+    //   }
161
+    // }
162
+    this.chart.setOption(option)
163
+  },
164
+  methods: {
165
+    xLabelFormat(name) {
166
+      const nameArr = []
167
+      for(let i=0; i<name.length; i+=6) {
168
+        nameArr.push(name.substring(i, i+6))
169
+      }
170
+      return nameArr.join('\n');
171
+    },
172
+    // tooltipFormat(params) {
173
+    //   const type = params[0].seriesType;
174
+    //   const data = params[0].data;
175
+    //   console.log(params[0].data, '333')
176
+    //   return `<div style="background: black">${data.hs || "--"}户</div>`;
177
+    // },
178
+  }
179
+}
180
+</script>
181
+
182
+<style lang="less">
183
+  .chart {
184
+    width: 100%;
185
+    height: 100%;
186
+  }
187
+</style>

+ 36 - 2
src/pages/homepage/components/cardWrap.vue

@@ -28,7 +28,22 @@
28 28
     <div class="chart-wrap">
29 29
       <div class="chart-card">
30 30
         <div class="title">各主题域资产数量统计</div>
31
-        <div class="chart"></div>
31
+        <div class="chart">
32
+          <barchart
33
+            class="side-chart"
34
+            :autoStop="false"
35
+            legendIcon="circle"
36
+            :bottom="90"
37
+            :xlabelFormat="xLabelFormat"
38
+            :top="60"
39
+            :yAxisName="['(张)', '(兆)']"
40
+            :tooltip="tooltipFormat"
41
+            :dataset="barData"
42
+            :encode="[{x: 'qyjc', y: 'hs', seriesName: '数据量'}, {x: 'qyjc', y: 'hs1', seriesName: '数据表'}]"
43
+            :labelSize="15"
44
+            id="dqfb"
45
+          />
46
+        </div>
32 47
       </div>
33 48
       <div class="chart-card">
34 49
         <div class="title">各专题资产数量统计</div>
@@ -47,7 +62,12 @@
47 62
 </template>
48 63
 <script>
49 64
 
65
+import barchart from "@/components/barChart";
66
+
50 67
 export default {
68
+    components: {
69
+      barchart
70
+    },
51 71
     data() {
52 72
         return {
53 73
           searchWords: '',
@@ -67,7 +87,8 @@ export default {
67 87
             title: '总线服务',
68 88
             new: 35,
69 89
             history: 1553,
70
-          }]
90
+          }],
91
+          barData: [{qyjc: '2023-01', hs: 100, hs1: 200}, {qyjc: '2023-02', hs: 10, hs1: 20}, {qyjc: '2023-03', hs: 10, hs1: 20}, {qyjc: '2023-04', hs: 10, hs1: 20}, {qyjc: '2023-05', hs: 10, hs1: 20},]
71 92
         }
72 93
     },
73 94
     mounted() {
@@ -85,6 +106,19 @@ export default {
85 106
           }
86 107
         });
87 108
       },
109
+      xLabelFormat(name) {
110
+        const nameArr = []
111
+        for(let i=0; i<name.length; i+=7) {
112
+          nameArr.push(name.substring(i, i+7))
113
+        }
114
+        return nameArr.join('\n');
115
+      },
116
+      tooltipFormat(params) {
117
+        const type = params[0].seriesType;
118
+        const data = params[0].data;
119
+        // ${params[0].name || "--"}月:
120
+        return `<div class="${type==='bar' ? 'bar-tooltip-dz' : type==='line' ? 'line-tooltip-dz' : ''}">${data.hs || "--"}张</div>`;
121
+      },
88 122
     }
89 123
 }
90 124
 </script>

+ 1 - 0
src/pages/homepage/homepage.html

@@ -5,6 +5,7 @@
5 5
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
6 6
     <title>数据资源首页</title>
7 7
     <script src="static/mung-local-config.js"></script>
8
+    <script src="static/jquery-3.1.0.min.js"></script>
8 9
   </head>
9 10
   <body>
10 11
     <div id="homepage" style="background: #f1f2f5"></div>

+ 3 - 0
src/pages/homepage/homepage.js

@@ -4,10 +4,13 @@ import "element-ui/lib/theme-chalk/index.css"
4 4
 import "../../assets/css/global.css"
5 5
 import homepage from './homepage.vue'
6 6
 import router from "../../router/homepage"
7
+import echarts from 'echarts'
8
+
7 9
 import config from '@/config/index';
8 10
 
9 11
 Vue.use(ElementUI);
10 12
 
13
+Vue.prototype.$echarts = echarts
11 14
 Vue.prototype.baseUrl =
12 15
   process.env.NODE_ENV !== "development"
13 16
     ? config.build.BASE_API

File diff suppressed because it is too large
+ 4 - 0
static/jquery-3.1.0.min.js