index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div shadow="never" class="homeBoxCard" v-loading="loading">
  3. <br>
  4. <div class="height300" ref="chainChartRef" />
  5. <br>
  6. </div>
  7. </template>
  8. <script>
  9. import { defineComponent, onMounted, ref, watch } from 'vue'
  10. import * as echarts from 'echarts'
  11. export default defineComponent({
  12. name: 'CurveCom',
  13. props: {
  14. echartsDataOne: Object,
  15. },
  16. setup(props) {
  17. const chainChartRef = ref(null)
  18. const resultListDate=ref([])
  19. // 读取数据 func
  20. const loading = ref(true)
  21. const getData = async () => {
  22. loading.value = false
  23. var aa = props.echartsDataOne.listDate
  24. var bb = props.echartsDataOne.listDate2
  25. resultListDate.value = aa.map(function (index, item) {
  26. return index +' - '+ bb[item]
  27. })
  28. }
  29. function echarts2() {
  30. let myChart = echarts.init(chainChartRef.value)
  31. // 绘制图表
  32. myChart.setOption({
  33. color: ['#FEB70D', '#50F335', '#0DC8FE'],
  34. title: {
  35. text: props.echartsDataOne.name,
  36. left: '2.5%',
  37. textStyle: {
  38. color: '#9d9d9d',
  39. fontSize: 14,
  40. fontWeight: 600,
  41. },
  42. },
  43. tooltip: {
  44. trigger: 'axis',
  45. },
  46. // 图列组件
  47. legend: {
  48. itemHeight: 10, //改变圆圈大小
  49. itemWidth: 26, //改变圆圈大小
  50. itemGap: 30,
  51. textStyle: {
  52. color: 'black',
  53. },
  54. left: 'center',
  55. // bottom: '0',
  56. },
  57. toolbox: {
  58. show: true,
  59. feature: {
  60. saveAsImage: { show: true, color: 'black' },
  61. },
  62. iconStyle: {
  63. borderColor: '#666',
  64. },
  65. },
  66. grid: {
  67. left: '3%',
  68. right: '4%',
  69. bottom: '5%',
  70. containLabel: true,
  71. },
  72. xAxis: {
  73. type: 'category',
  74. boundaryGap: true,
  75. data: props.echartsDataOne ? resultListDate.value : [],
  76. axisTick: {
  77. show: true, //去除刻度线
  78. },
  79. // axisLabel:false,
  80. // axisLabel: {
  81. // interval:0,
  82. // rotate:"-12",
  83. // color: 'black', // 文本颜色
  84. // },
  85. axisLine: {
  86. show: false, // 去除轴线
  87. },
  88. },
  89. yAxis: {
  90. nameTextStyle: {
  91. color: 'black',
  92. fontSize: 10,
  93. },
  94. type: 'value',
  95. axisTick: {
  96. show: true, //去除刻度线
  97. },
  98. axisLabel: {
  99. color: 'black', // 文本颜色
  100. },
  101. axisLine: {
  102. show: true, // 去除轴线
  103. lineStyle: {
  104. color: 'black',
  105. },
  106. },
  107. splitNumber: 5,
  108. splitLine: {
  109. show: true,
  110. lineStyle: {
  111. color: '#9d9d9d',
  112. },
  113. },
  114. },
  115. series: [
  116. {
  117. name: '本期',
  118. type: 'line',
  119. smooth: false,
  120. data: props.echartsDataOne.list2,
  121. symbolSize: 6,
  122. markPoint: {
  123. data: [
  124. { type: 'max', name: 'Max' },
  125. { type: 'min', name: 'Min' },
  126. ],
  127. },
  128. },
  129. {
  130. name: '上期',
  131. type: 'line',
  132. smooth: false,
  133. data: props.echartsDataOne.list,
  134. symbolSize: 6,
  135. markPoint: {
  136. data: [
  137. { type: 'max', name: 'Max' },
  138. { type: 'min', name: 'Min' },
  139. ],
  140. },
  141. },
  142. ],
  143. })
  144. window.onresize = function () {
  145. // 自适应大小
  146. myChart.resize()
  147. }
  148. }
  149. const writeValue = (val) => {
  150. val
  151. getData()
  152. echarts2()
  153. }
  154. //监听变化
  155. watch(
  156. () => props.echartsDataOne,
  157. (newVal, oldVal, clear) => {
  158. // 执行异步任务,并得到关闭异步任务的 id
  159. // console.log(newVal)
  160. let id = writeValue(newVal, oldVal)
  161. // 如果 watch 监听被重复执行了,则会先清除上次未完成的异步任务
  162. clear(() => clearTimeout(id))
  163. },
  164. { lazy: true }
  165. )
  166. onMounted(() => {
  167. getData()
  168. echarts2()
  169. })
  170. return {
  171. chainChartRef,
  172. loading,
  173. echarts,
  174. resultListDate
  175. }
  176. },
  177. })
  178. </script>
  179. <style lang="scss" scoped>
  180. .homeBoxCard {
  181. // margin-bottom: 24px;
  182. ::v-deep(.el-card__header) {
  183. padding-left: 12px;
  184. padding-right: 12px;
  185. }
  186. ::v-deep(.el-card__body) {
  187. padding: 12px;
  188. font-size: 14px;
  189. line-height: 1.5715;
  190. }
  191. ::v-deep(.el-divider) {
  192. margin: 8px 0;
  193. }
  194. .num {
  195. font-size: 30px;
  196. color: #515a6e;
  197. }
  198. .height300 {
  199. height: 15rem;
  200. }
  201. }
  202. </style>