index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <div class="data_body">
  3. <div style="width: 100%; height: 100%">
  4. <div id="charts_canvas" class="echart" style="width: 100%; height: 100%; "></div>
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. export default {
  10. props: {
  11. evCourseArray: {
  12. type: Array,
  13. default: []
  14. },
  15. eva: {
  16. type: String,
  17. default: ''
  18. }
  19. },
  20. data() {
  21. return {
  22. chartObj: null,
  23. ooption: {
  24. xdata: [],
  25. sdata: [],
  26. },
  27. option: {
  28. xAxis: {
  29. type: 'value',
  30. show:false,
  31. },
  32. grid:{
  33. left: '15%',
  34. right: '5%',
  35. bottom: '5%',
  36. top: '5%',
  37. },
  38. yAxis: {
  39. inverse: true,
  40. type: 'category',
  41. data: [
  42. '休闲状态(<=50%)',
  43. '热身状态(50-60%)',
  44. '脂肪燃烧(60-70%)',
  45. '心肺提升(70-80%)',
  46. '乳酸闽值(80-90%)',
  47. '极限无氧(>=90%)'
  48. ]
  49. },
  50. series: [
  51. {
  52. showBackground: true,
  53. data: [
  54. {
  55. value: 10,
  56. itemStyle: {
  57. color: 'rgb(157, 157, 157)'
  58. }
  59. },
  60. {
  61. value: 20,
  62. itemStyle: {
  63. color: 'rgb(15, 216, 242)'
  64. }
  65. },
  66. {
  67. value: 40,
  68. itemStyle: {
  69. color: 'rgb(0, 208, 146)'
  70. }
  71. },
  72. {
  73. value: 80,
  74. itemStyle: {
  75. color: 'rgb(255, 192, 29)'
  76. }
  77. },
  78. {
  79. value: 70,
  80. itemStyle: {
  81. color: 'rgb(247, 123, 1)'
  82. }
  83. },
  84. {
  85. value: 15,
  86. itemStyle: {
  87. color: 'rgb(255, 58, 32)'
  88. }
  89. },
  90. ],
  91. type: 'bar'
  92. }
  93. ]
  94. },
  95. };
  96. },
  97. methods: {
  98. setChart(option) {
  99. // 雷达图显示的标签
  100. let newPromise = new Promise((resolve) => {
  101. resolve();
  102. });
  103. //然后异步执行echarts的初始化函数
  104. newPromise.then(() => {
  105. const chartObj = this.$echarts.init(
  106. //劳动课程
  107. this.$el.querySelector("#charts_canvas")
  108. );
  109. // this.option.radar.indicator = option.xdata;
  110. // this.option.series[0].data[0].value = option.sdata;
  111. // 初始化雷达图
  112. this.chartObj = chartObj;
  113. this.chartObj.setOption(this.option);
  114. });
  115. },
  116. setArray(array) {
  117. this.setChart(array);
  118. return
  119. this.ooption = {
  120. xdata: [],
  121. sdata: [],
  122. }
  123. for (var i = 0; i < array.length; i++) {
  124. if (array[i].evid == this.eva) {
  125. this.ooption.xdata = array[i].indicator
  126. this.ooption.sdata = array[i].value
  127. break;
  128. }
  129. }
  130. setTimeout(() => {
  131. // if (!this.chartObj) {
  132. this.setChart(this.ooption);
  133. // } else {
  134. // this.option.radar.indicator = this.ooption.xdata;
  135. // this.option.series[0].data[0].value = this.ooption.sdata;
  136. // this.chartObj.setOption(this.option);
  137. // }
  138. }, 100);
  139. this.$forceUpdate();
  140. },
  141. },
  142. watch: {
  143. evCourseArray: {
  144. immediate: true,
  145. deep: true,
  146. handler(newValue, oldValue) {
  147. this.setArray(newValue)
  148. this.$forceUpdate();
  149. },
  150. },
  151. eva: {
  152. immediate: true,
  153. deep: true,
  154. handler(newValue, oldValue) {
  155. this.setArray(this.evCourseArray)
  156. this.$forceUpdate();
  157. },
  158. },
  159. },
  160. mounted() {
  161. this.setArray(this.evCourseArray)
  162. // this.setChart(this.ooption);
  163. var _this = this;
  164. window.addEventListener("resize", () => {
  165. if (_this.chartObj) {
  166. _this.chartObj.resize();
  167. }
  168. });
  169. },
  170. };
  171. </script>
  172. <style scoped>
  173. .data_body {
  174. height: 100%;
  175. /* display: flex; */
  176. position: relative;
  177. border-radius: 5px;
  178. /* border: 1px solid #eee; */
  179. margin: 0 auto;
  180. box-sizing: border-box;
  181. padding: 0;
  182. width: 95%;
  183. background: #fff;
  184. }
  185. </style>