index.vue 5.4 KB

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