ChartStep.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <div>
  3. <common ref="common" @asynCallBack="asynCallBack"></common>
  4. <top-header :pageTitle="pageTitle"></top-header>
  5. <div class="mui-content vongi-yjcsdat">
  6. <div class="mui-content-padded">
  7. <h2>{{pageTitle}}趋势图</h2>
  8. <div id="linePicture" style="width:100%;height: 300px;">
  9. </div>
  10. </div>
  11. <h4 class="colorfe616c">测量仅供参考,不作为临床诊断使用</h4>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. import * as API_Health from '@/apis/Master/health'
  17. import Common from '$project/components/Common.vue'
  18. import Loading from '$project/components/Loading.vue'
  19. import TopHeader from '$project/components/TopHeader.vue'
  20. import NavMenu from '@/components/NavMenu.vue'
  21. import {
  22. mapGetters,
  23. mapMutations
  24. } from 'vuex'
  25. import echarts from 'echarts/lib/echarts'
  26. import 'echarts/lib/chart/line'
  27. import 'echarts/lib/component/legend'
  28. import 'echarts/lib/component/title'
  29. import 'echarts/lib/component/tooltip'
  30. export default {
  31. name: 'MasterHealthChartStep',
  32. components: {
  33. Common,
  34. Loading,
  35. TopHeader,
  36. NavMenu
  37. },
  38. data() {
  39. return {
  40. isLoading: false,
  41. pageTitle: this.$route.query.title,
  42. listForm: {
  43. names: this.$route.query.type,
  44. },
  45. typeList: '',
  46. chartsList: [],
  47. }
  48. },
  49. created() {
  50. this.typeList = this.$route.query.type.split(',');
  51. },
  52. methods: {
  53. //获取图表数据
  54. getChartList() {
  55. this.isLoading = true;
  56. API_Health.getChartList(this.listForm).then(response => {
  57. this.isLoading = false;
  58. this.chartsList = response;
  59. this.setEcharts();
  60. }).catch(error => {
  61. this.isLoading = false;
  62. mui.toast(error);
  63. })
  64. },
  65. //设置echart数据
  66. setEcharts() {
  67. var legendData = [];
  68. var xAxisData = [];
  69. var series = [];
  70. for (var i = 0; i < this.typeList.length; i++) {
  71. var seriesData = [];
  72. legendData.push(this.chartsList[this.typeList[i]].name);
  73. var list = this.chartsList[this.typeList[i]].list;
  74. for (var j = 0; j < list.length; j++) {
  75. if (i == 0) {
  76. xAxisData.push(list[j].recordTime);
  77. }
  78. seriesData.push(list[j].value);
  79. }
  80. series.push({
  81. name: this.chartsList[this.typeList[i]].name,
  82. type: 'line',
  83. stack: '',
  84. data: seriesData
  85. });
  86. }
  87. this.echarts(legendData, xAxisData, series);
  88. },
  89. //显示图表
  90. echarts(legendData, xAxisData, series) {
  91. this.$nextTick(() => {
  92. // 基于准备好的dom,初始化echarts实例
  93. var myChart = echarts.init(document.getElementById('linePicture'));
  94. // 指定图表的配置项和数据
  95. var option = {
  96. tooltip: {
  97. trigger: 'axis',
  98. },
  99. legend: {
  100. data: legendData,
  101. orient: 'horizontal',
  102. x: 'center',
  103. y: 'bottom',
  104. },
  105. grid: {
  106. left: '3%',
  107. right: '4%',
  108. bottom: '10%',
  109. x: 40,
  110. x2: 30,
  111. y: 20,
  112. containLabel: true
  113. },
  114. xAxis: {
  115. type: 'category',
  116. boundaryGap: false,
  117. data: xAxisData,
  118. axisLabel: {
  119. interval: 0,
  120. rotate: 80
  121. }
  122. },
  123. yAxis: {
  124. type: 'value',
  125. axisLabel: {
  126. interval: 0,
  127. rotate: 40
  128. }
  129. },
  130. series: series
  131. };
  132. // 使用刚指定的配置项和数据显示图表。
  133. myChart.setOption(option);
  134. /* myChart.resize({
  135. height: rHeight + 'px'
  136. }) */
  137. });
  138. },
  139. asynCallBack() {},
  140. },
  141. mounted() {
  142. //获取图表数据
  143. this.getChartList();
  144. },
  145. destroyed() {
  146. },
  147. computed: {
  148. ...mapGetters({
  149. openId: 'wx_openid',
  150. token: 'token',
  151. person_data: 'person_data',
  152. person_popedom: 'person_popedom',
  153. menu_list: 'menu_list',
  154. common_menu_list: 'common_menu_list',
  155. persion_home_model: 'persion_home_model'
  156. })
  157. }
  158. }
  159. </script>
  160. <style scoped src="$project/assets/css/pension.css"></style>
  161. <style scoped src="$project/assets/css/xpwyfyy.css"></style>
  162. <style src="$project/assets/css/iconfont.css"></style>
  163. <style>
  164. </style>