See999 4 år sedan
förälder
incheckning
335d44d1e4

+ 262 - 0
src/xt_pages/qcd/components/LineChart1.vue Visa fil

@@ -0,0 +1,262 @@
1
+<template>
2
+  <div :class="className" :style="{height:height,width:width}"></div>
3
+</template>
4
+
5
+<script>
6
+import echarts from "echarts";
7
+require("echarts/theme/macarons"); // echarts theme
8
+import { debounce } from "@/utils";
9
+
10
+export default {
11
+  props: {
12
+    className: {
13
+      type: String,
14
+      default: "chart"
15
+    },
16
+    width: {
17
+      type: String,
18
+      default: "100%"
19
+    },
20
+    height: {
21
+      type: String,
22
+      default: "230px"
23
+    },
24
+    autoResize: {
25
+      type: Boolean,
26
+      default: true
27
+    },
28
+    chartData: {
29
+      type: Object
30
+    },
31
+    title: {
32
+      type: String,
33
+      default: "chart"
34
+    },
35
+    options: {
36
+      type: Object,
37
+      default: function() {
38
+        return {};
39
+      }
40
+    }
41
+  },
42
+  data() {
43
+    return {
44
+      chart: null,
45
+      chartOptions: {
46
+        xAxis: [],
47
+        legend: [],
48
+        series: []
49
+      }
50
+    };
51
+  },
52
+  mounted() {
53
+    this.initChart();
54
+    if (this.autoResize) {
55
+      this.__resizeHanlder = debounce(() => {
56
+        if (this.chart) {
57
+          this.chart.resize();
58
+        }
59
+      }, 100);
60
+      window.addEventListener("resize", this.__resizeHanlder);
61
+    }
62
+
63
+    // 监听侧边栏的变化
64
+    const sidebarElm = document.getElementsByClassName("sidebar-container")[0];
65
+    sidebarElm.addEventListener("transitionend", this.__resizeHanlder);
66
+  },
67
+  beforeDestroy() {
68
+    if (!this.chart) {
69
+      return;
70
+    }
71
+    if (this.autoResize) {
72
+      window.removeEventListener("resize", this.__resizeHanlder);
73
+    }
74
+
75
+    const sidebarElm = document.getElementsByClassName("sidebar-container")[0];
76
+    sidebarElm.removeEventListener("transitionend", this.__resizeHanlder);
77
+
78
+    this.chart.dispose();
79
+    this.chart = null;
80
+  },
81
+  watch: {
82
+    // options: function(a) {
83
+    //   console.log(a)
84
+    //   this.chartOptions = this.options;
85
+    //   this.initChart();
86
+    //   this.__resizeHanlder = debounce(() => {
87
+    //     if (this.chart) {
88
+    //       this.chart.resize();
89
+    //     }
90
+    //   }, 100);
91
+    //   window.addEventListener("resize", this.__resizeHanlder);
92
+    // },
93
+    options:{
94
+      handler(newValue,oldValue){
95
+        this.getInitChart();
96
+      },
97
+      deep:true
98
+    },
99
+
100
+    chartData: {
101
+      deep: true,
102
+      handler(val) {
103
+        this.setOptions(val);
104
+      }
105
+    }
106
+  },
107
+  created() {
108
+    this.chartOptions = this.options;
109
+    // console.log("this.chartOptions", this.chartOptions, this.options);
110
+  },
111
+  methods: {
112
+    getInitChart() {
113
+      this.chartOptions = this.options;
114
+      this.initChart();
115
+      this.__resizeHanlder = debounce(() => {
116
+        if (this.chart) {
117
+          this.chart.resize();
118
+        }
119
+      }, 100);
120
+      window.addEventListener("resize", this.__resizeHanlder);
121
+    },
122
+    // setOptions({ expectedData, actualData } = {}) {
123
+    //   this.chart.setOption({
124
+    //     title: {
125
+    //         text: this.title,
126
+    //     },
127
+    //     xAxis: {
128
+    //       data: this.chartOptions.xAxis,
129
+    //       boundaryGap: false,
130
+    //       axisTick: {
131
+    //         show: false
132
+    //       }
133
+    //     },
134
+    //     grid: {
135
+    //       left: 50,
136
+    //       right: 50,
137
+    //       bottom: 20,
138
+    //       top: 30,
139
+    //       containLabel: true
140
+    //     },
141
+    //     tooltip: {
142
+    //       trigger: 'axis',
143
+    //       axisPointer: {
144
+    //         type: 'cross'
145
+    //       },
146
+    //       padding: [5, 10]
147
+    //     },
148
+    //     yAxis: {
149
+    //       axisTick: {
150
+    //         show: false
151
+    //       }
152
+    //     },
153
+    //     legend: {
154
+    //       data: this.chartOptions.legend,
155
+    //     },
156
+    //     series: this.chartOptions.series,
157
+    //   })
158
+    // },
159
+    setOptions({ expectedData, actualData } = {}) {
160
+      this.chart.setOption({
161
+        // title: {
162
+        //   text: this.title
163
+        // },
164
+        xAxis: {
165
+          data: this.chartOptions.xAxis.data,
166
+          // boundaryGap: false
167
+          axisTick: {
168
+            show: true
169
+          },
170
+          axisLine: {
171
+            lineStyle: {
172
+              color: "#E5E5E5" //x轴颜色
173
+            }
174
+          },
175
+          axisLabel: {
176
+            interval: 0,
177
+            formatter: function(value) {
178
+              var ret = ""; //拼接加\n返回的类目项
179
+              var maxLength = 10; //每项显示文字个数
180
+              var valLength = value.length; //X轴类目项的文字个数
181
+              var rowN = Math.ceil(valLength / maxLength); //类目项需要换行的行数
182
+              if (rowN > 1) {
183
+                //如果类目项的文字大于3,
184
+                for (var i = 0; i < rowN; i++) {
185
+                  var temp = ""; //每次截取的字符串
186
+                  var start = i * maxLength; //开始截取的位置
187
+                  var end = start + maxLength; //结束截取的位置
188
+                  //这里也可以加一个是否是最后一行的判断,但是不加也没有影响,那就不加吧
189
+                  temp = value.substring(start, end) + "\n";
190
+                  ret += temp; //凭借最终的字符串
191
+                }
192
+                return ret;
193
+              } else {
194
+                return value;
195
+              }
196
+            },
197
+            textStyle: {
198
+              color:"#2F3133"
199
+            }
200
+          }
201
+        },
202
+        grid: {
203
+          left: 0,
204
+          right: 50,
205
+          bottom: 10,
206
+          top: 30,
207
+          containLabel: true
208
+        },
209
+        tooltip: {
210
+          trigger: "axis",
211
+          axisPointer: {
212
+            type: "cross"
213
+          },
214
+          padding: [5, 10]
215
+        },
216
+        yAxis: {
217
+          axisTick: {
218
+            show: true
219
+          },
220
+          axisLine: {
221
+            lineStyle: {
222
+              color: "#E5E5E5" //y轴颜色
223
+            },
224
+          },
225
+          axisLabel: {
226
+            textStyle: {
227
+              color:"#2F3133"
228
+            }
229
+          },
230
+          max:2
231
+        },
232
+        // dataZoom: [
233
+        //   {
234
+        //     //Y轴固定,让内容滚动
235
+        //     type: "slider",
236
+        //     show: false,
237
+        //     xAxisIndex: [0],
238
+        //     start: 1,
239
+        //     end: 80, //设置X轴刻度之间的间隔(根据数据量来调整)
240
+        //     zoomLock: true //锁定区域禁止缩放(鼠标滚动会缩放,所以禁止)
241
+        //   },
242
+        //   {
243
+        //     type: "inside",
244
+        //     xAxisIndex: [0],
245
+        //     start: 1,
246
+        //     end: 80,
247
+        //     zoomLock: true //锁定区域禁止缩放
248
+        //   }
249
+        // ],
250
+        legend: this.chartOptions.legend,
251
+        series: this.chartOptions.series,
252
+        dataZoom: this.chartOptions.dataZoom,
253
+      });
254
+    },
255
+    initChart() {
256
+      this.chart = echarts.init(this.$el, "macarons");
257
+      this.chart.clear();
258
+      this.setOptions(this.chartData);
259
+    }
260
+  }
261
+};
262
+</script>

+ 67 - 22
src/xt_pages/qcd/indicatorControlAnalysis/patientInspectionDetail.vue Visa fil

@@ -101,7 +101,7 @@
101 101
           <div>
102 102
             <!--<line-chart :options="options2"></line-chart>-->
103 103
             <line-chart v-if="this.$route.query.range_type == 1" :options="options"></line-chart>
104
-            <line-chart v-if="this.$route.query.range_type == 2" :options="options2"></line-chart>
104
+            <line-chart1 v-if="this.$route.query.range_type == 2" :options="options2"></line-chart1>
105 105
 
106 106
 
107 107
 
@@ -118,6 +118,7 @@
118 118
   const moment = require('moment')
119 119
   import echarts from 'echarts'
120 120
   import LineChart from '../../qcd/components/LineChart'
121
+  import LineChart1 from '../../qcd/components/LineChart1'
121 122
   import { uParseTime } from '@/utils/tools'
122 123
   import BreadCrumb from '@/xt_pages/components/bread-crumb'
123 124
   import { getCurrentOrgPatients } from '@/api/common/common'
@@ -136,6 +137,7 @@
136 137
     name: 'dialysisTotal',
137 138
     components: {
138 139
       LineChart,
140
+      LineChart1,
139 141
       BreadCrumb
140 142
     },
141 143
     data() {
@@ -200,12 +202,19 @@
200 202
               name: '',
201 203
               type: 'line',
202 204
               data: [],
205
+              symbol: 'circle',//折线点设置为实心点
206
+              symbolSize: 15,   //折线点的大小
203 207
               barWidth: 30,
204 208
               label: {
205 209
                 normal: {
206 210
                   show: true,
207
-                  position: 'top',
208
-                  formatter: '{c}'
211
+                  position: "top",
212
+                  formatter: (params) => {
213
+                      let str = ''
214
+                      str = this.otherData[params.dataIndex]
215
+                      return str
216
+
217
+                  }
209 218
                 }
210 219
               },
211 220
               //配置样式
@@ -214,24 +223,33 @@
214 223
 
215 224
                 //每个柱子的颜色即为colorList数组里的每一项,如果柱子数目多于colorList的长度,则柱子颜色循环使用该数组
216 225
                 normal: {
217
-                  color: function(params) {
226
+                  color: (params) => {
218 227
                     //我这边就两个柱子,大体就两个柱子颜色渐变,所以数组只有两个值,多个颜色就多个值
219
-                    var colorList = [
220
-                      ['#A9E0F3', '#9FBDFC'],
221
-
222
-                      ['#FFD7C0', '#FF9994']
223
-                    ]
224
-
225
-                    var index = params.dataIndex
226
-                    if (params.dataIndex >= colorList.length) {
227
-                      index = params.dataIndex % colorList.length
228
-                    }
229
-
230
-                    return new echarts.graphic.LinearGradient(0, 0, 0, 1, [
231
-                      { offset: 0, color: colorList[index][0] },
232
-                      // { offset: 0.5, color: colorList[index][1] },
233
-                      { offset: 1, color: colorList[index][1] }
234
-                    ])
228
+                    var colorList = [
229
+                      ['#409EFF','#409EFF'],
230
+                      ['#f56c6c','#f56c6c']
231
+                      ];
232
+                    if(params.seriesName == this.otherData[params.dataIndex]){
233
+                      var index = 0 
234
+                    }else {
235
+                      var index = 1
236
+                    }
237
+                   
238
+
239
+                    // var index = params.dataIndex;
240
+                    // if (params.dataIndex >= colorList.length) {
241
+                    //   index = params.dataIndex % colorList.length;
242
+                    // }
243
+
244
+                    return new echarts.graphic.LinearGradient(0, 0, 0, 1, [
245
+                      {offset: 0, color: colorList[index][0]},
246
+                      // { offset: 0.5, color: colorList[index][1] },
247
+                      {offset: 1, color: colorList[index][1]}
248
+                    ]);
249
+                  },
250
+                  lineStyle: {
251
+                    width:2,
252
+                    color: "#cccccc"//折线的颜色
235 253
                   },
236 254
                   barBorderRadius: [5, 5, 0, 0] //柱状角成椭圆形
237 255
                 },
@@ -449,7 +467,8 @@
449 467
           { value: 4, label: '近一年', state: 4 },
450 468
           { value: 5, label: '自定义', state: 5 }
451 469
         ],
452
-        search_value: ''
470
+        search_value: '',
471
+        otherData:[]
453 472
       }
454 473
     },
455 474
     methods: {
@@ -599,9 +618,15 @@
599 618
                   this.options2.xAxis.data.push(resp.data.data[i].date)
600 619
                   tempData.push(resp.data.data[i].value)
601 620
                   otherData.push(resp.data.data[i].value)
621
+                  this.options2.series[0].name = resp.data.references.range_value
602 622
                 }
603 623
               }
604
-
624
+              this.otherData = otherData
625
+              if(this.$route.query.range_type == 1){
626
+                this.getArrLength(this.options.xAxis.data,1)
627
+              }else{
628
+                this.getArrLength(this.options2.xAxis.data,this.$route.query.range_type)
629
+              }
605 630
               console.log(this.options.xAxis.data)
606 631
 
607 632
               console.log(this.options.series[0].data)
@@ -641,6 +666,26 @@
641 666
       }, getTimestamp(time) {
642 667
         // 把时间日期转成时间戳
643 668
         return new Date(time).getTime() / 1000
669
+      },
670
+      getArrLength(result,type){
671
+        if(type == 1){
672
+          if(result.length > 10){
673
+            var dataZoom_end = (10/result.length)*100;
674
+            this.options.dataZoom[0].end = dataZoom_end
675
+          }else{
676
+            var dataZoom_end = 100;
677
+            this.options.dataZoom[0].end = dataZoom_end
678
+          }
679
+        }else{
680
+          if(result.length > 10){
681
+            var dataZoom_end = (10/result.length)*100;
682
+            this.options2.dataZoom[0].end = dataZoom_end
683
+          }else{
684
+            var dataZoom_end = 100;
685
+            this.options2.dataZoom[0].end = dataZoom_end
686
+          }
687
+        }
688
+
644 689
       }
645 690
 
646 691
     },