gasInjectChart.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <div ref="gasInjectChart" class="inject-echart-box"></div>
  3. </template>
  4. <script setup lang="ts">
  5. import { nextTick, ref, onMounted, reactive, watch } from 'vue'
  6. import * as echarts from 'echarts';
  7. let props = defineProps({
  8. option: {
  9. type: Object as any
  10. },
  11. echartData: {
  12. type: Object as any
  13. }
  14. })
  15. let gasInjectChart = ref(null)
  16. //图表数据
  17. let echartDatas = reactive({}) as any
  18. let xLabel = ['3.26', '3.27', '3.28', '3.29', '3.30', '3.31']
  19. let goToSchool = ["40", "60", "22", "85", "50", "40"]
  20. let goOutSchool = ["20", "50", "12", "65", "30", "60"]
  21. function getOption() {
  22. nextTick(() => {
  23. let myChart = echarts.init(gasInjectChart.value);
  24. let option
  25. if (props.option.type == 'bar_lt') {
  26. option = {
  27. tooltip: props.option.tooltip,
  28. grid: props.option.grid,
  29. legend: props.option.legend,
  30. xAxis: [{
  31. data: echartDatas.xData,
  32. axisLabel: {
  33. textStyle: {
  34. color: 'rgba(181, 185, 191)',
  35. fontSize: 12
  36. },
  37. margin: 10, //刻度标签与轴线之间的距离。
  38. },
  39. axisLine: {
  40. lineStyle: {
  41. color: 'rgba(1, 63, 97)',
  42. },
  43. },
  44. axisTick: {
  45. show: false //不显示刻度
  46. },
  47. boundaryGap: true,
  48. splitLine: {
  49. show: false,
  50. },
  51. }],
  52. yAxis: props.option.yAxis,
  53. series: props.option.series.map(el => {
  54. return {
  55. ...el,
  56. data: echartDatas[el.data]
  57. }
  58. })
  59. };
  60. } else if (props.option.type == 'line-area') {
  61. option = {
  62. tooltip: props.option.tooltip,
  63. grid: props.option.grid,
  64. xAxis: [{
  65. type: 'category',
  66. boundaryGap: false,
  67. axisLine: { //坐标轴轴线相关设置。数学上的x轴
  68. show: true,
  69. lineStyle: {
  70. color: 'rgba(1, 63, 97)',
  71. },
  72. },
  73. axisLabel: { //坐标轴刻度标签的相关设置
  74. textStyle: {
  75. color: 'rgba(181, 185, 191)',
  76. padding: 5,
  77. fontSize: 12
  78. },
  79. formatter: function (data) {
  80. return data
  81. }
  82. },
  83. splitLine: {
  84. show: false,
  85. },
  86. axisTick: {
  87. show: false,
  88. },
  89. data: xLabel
  90. }],
  91. yAxis: [{
  92. name: '(MPa)',
  93. nameTextStyle: {
  94. color: 'rgba(181, 185, 191)',
  95. fontSize: 12,
  96. padding: 0
  97. },
  98. min: 0,
  99. splitLine: {
  100. show: true,
  101. lineStyle: {
  102. color: 'rgba(1, 63, 97)',
  103. },
  104. },
  105. axisLine: {
  106. show: false,
  107. },
  108. axisLabel: {
  109. show: true,
  110. textStyle: {
  111. color: 'rgba(181, 185, 191)',
  112. padding: 12
  113. },
  114. formatter: '{value}',
  115. },
  116. axisTick: {
  117. show: false,
  118. },
  119. }],
  120. series: [{
  121. name: '',
  122. type: 'line',
  123. symbol: 'circle', // 默认是空心圆(中间是白色的),改成实心圆
  124. showAllSymbol: true,
  125. symbolSize: 0,
  126. smooth: true,
  127. lineStyle: {
  128. normal: {
  129. width: 3,
  130. color: props.option.colorLine, // 线条颜色
  131. },
  132. borderColor: 'rgba(0,0,0,.4)',
  133. },
  134. itemStyle: {
  135. color: props.option.colorLine,
  136. borderColor: "#646ace",
  137. borderWidth: 2
  138. },
  139. areaStyle: { //区域填充样式
  140. normal: {
  141. //线性渐变,前4个参数分别是x0,y0,x2,y2(范围0~1);相当于图形包围盒中的百分比。如果最后一个参数是‘true’,则该四个值是绝对像素位置。
  142. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  143. offset: 0,
  144. color: props.option.colorArea[0]
  145. },
  146. {
  147. offset: 1,
  148. color: props.option.colorArea[1]
  149. }
  150. ], false),
  151. shadowColor: 'rgba(255, 157, 29, 0.5)', //阴影颜色
  152. shadowBlur: 20 //shadowBlur设图形阴影的模糊大小。配合shadowColor,shadowOffsetX/Y, 设置图形的阴影效果。
  153. }
  154. },
  155. data: goToSchool
  156. },
  157. ]
  158. };
  159. }
  160. myChart.setOption(option);
  161. window.onresize = function () {
  162. myChart.resize();
  163. };
  164. });
  165. }
  166. watch(() => props.echartData, (newV, oldV) => {
  167. console.log(newV, '单元抽采数据')
  168. if (newV) {
  169. echartDatas.xData = newV.map(el => el.typeName)
  170. echartDatas.yData = newV.map(el => el.datalist[0].readData.mixStdInstant)
  171. echartDatas.yData1 = newV.map(el => el.datalist[0].readData.gasConcentration)
  172. getOption()
  173. }
  174. }, { immediate: true })
  175. </script>
  176. <style lang="less" scoped>
  177. .inject-echart-box {
  178. width: 100%;
  179. height: 100%;
  180. }
  181. </style>