fanEchrats.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <div ref="chartRef" :style="{ height, width }"></div>
  3. </template>
  4. <script lang="ts">
  5. import { defineComponent, onMounted, PropType, reactive, Ref, ref, watchEffect } from 'vue';
  6. import { useECharts } from '/@/hooks/web/useECharts';
  7. import type { EChartsOption } from 'echarts';
  8. export default defineComponent({
  9. name: 'FanEcharts',
  10. props: {
  11. chartData: {
  12. type: Object,
  13. required: true,
  14. },
  15. xMin: {
  16. type: Number,
  17. default: 0,
  18. },
  19. xMax: {
  20. type: Number,
  21. default: 400,
  22. },
  23. width: {
  24. type: String as PropType<string>,
  25. default: '500px',
  26. },
  27. height: {
  28. type: String as PropType<string>,
  29. default: '400px',
  30. },
  31. },
  32. setup(props) {
  33. const chartRef = ref<HTMLDivElement | null>(null);
  34. const { setOptions, echarts, getInstance } = useECharts(chartRef as Ref<HTMLDivElement>);
  35. const dataX = ref([1, 2, 3, 4, 5, 6]);
  36. const dataY1 = ref([10, 43, 33, 13, 5, 34]);
  37. const dataY2 = ref([12, 54, 34, 65, 23, 43]);
  38. const dataY3 = ref([]);
  39. const option = reactive<EChartsOption>({
  40. color: ['#0083C4', '#50006A', '#ff0000', '#EE6666'],
  41. tooltip: {
  42. trigger: 'axis',
  43. axisPointer: {
  44. type: 'shadow',
  45. label: {
  46. show: true,
  47. backgroundColor: '#333',
  48. },
  49. },
  50. formatter: function (params: any, ticket, callback) {
  51. let res = '风量' + ' : ' + Math.round(params.data[0] * 60 * 10) / 10 + '(m³/min)<br/>';
  52. res = res + '&emsp;&emsp;&emsp;' + params.data[0] + '(m³/s)<br/>';
  53. res = res + '负压' + ' : ' + params.data[1] + '(Pa)<br/>';
  54. return res;
  55. },
  56. // trigger: 'item',
  57. },
  58. grid: {
  59. left: 70,
  60. right: 60,
  61. bottom: 50,
  62. top: 70,
  63. },
  64. xAxis: [
  65. {
  66. name: '风量(m³/min)',
  67. nameGap: 25,
  68. nameRotate: -45,
  69. type: 'value',
  70. // data: dataX.value,
  71. nameTextStyle: {
  72. fontWeight: 'bold',
  73. fontSize: '14px',
  74. color: '#000000',
  75. },
  76. axisLine: {
  77. show: false,
  78. lineStyle: {
  79. color: '#000000',
  80. },
  81. },
  82. splitLine: {
  83. show: false, // 网格线
  84. },
  85. axisLabel: {
  86. fontWeight: 'bold',
  87. fontSize: '14px',
  88. color: '#000000',
  89. },
  90. min: props.xMin * 60,
  91. max: props.xMax * 60,
  92. },
  93. {
  94. show: false,
  95. nameGap: 15,
  96. nameRotate: -45,
  97. type: 'value',
  98. // data: dataX.value,
  99. nameTextStyle: {
  100. fontWeight: 'bold',
  101. fontSize: '14px',
  102. color: '#000000',
  103. },
  104. splitLine: {
  105. show: true, // 网格线
  106. lineStyle: {
  107. type: 'dashed', // 设置网格线类型 dotted:虚线 solid:实线
  108. },
  109. },
  110. axisLine: {
  111. show: true,
  112. lineStyle: {
  113. color: '#000000',
  114. },
  115. },
  116. axisLabel: {
  117. show: true,
  118. fontWeight: 'bold',
  119. fontSize: '14px',
  120. color: '#000000',
  121. },
  122. min: props.xMin,
  123. max: props.xMax,
  124. },
  125. ],
  126. legend: {
  127. data: ['阻力(Nu)', '负压(Pa)'],
  128. top: '0px',
  129. textStyle: {
  130. color: '#000000',
  131. fontWeight: 'bold',
  132. fontSize: '14px',
  133. },
  134. },
  135. yAxis: [
  136. {
  137. min: 0,
  138. type: 'value',
  139. name: '负压(Pa)',
  140. nameGap: 30,
  141. splitNumber: 5,
  142. position: 'left',
  143. alignTicks: true,
  144. splitLine: {
  145. lineStyle: {
  146. color: '#00000022',
  147. type: 'dashed',
  148. },
  149. },
  150. axisLine: {
  151. show: true,
  152. lineStyle: {
  153. color: '#000000',
  154. },
  155. },
  156. axisLabel: {
  157. formatter: '{value}',
  158. fontWeight: 'bold',
  159. fontSize: '14px',
  160. },
  161. nameTextStyle: {
  162. fontWeight: 'bold',
  163. fontSize: '14px',
  164. },
  165. },
  166. ],
  167. series: [
  168. {
  169. name: '阻力(Nu)',
  170. type: 'line',
  171. data: dataY1.value,
  172. smooth: true,
  173. animationDuration: 1000,
  174. showSymbol: false,
  175. xAxisIndex: 1,
  176. yAxisIndex: 0,
  177. },
  178. {
  179. name: '负压(Pa)',
  180. type: 'line',
  181. data: dataY2.value,
  182. smooth: true,
  183. animationDuration: 1000,
  184. showSymbol: false,
  185. xAxisIndex: 1,
  186. yAxisIndex: 0,
  187. },
  188. {
  189. name: '',
  190. yAxisIndex: 0,
  191. xAxisIndex: 1,
  192. type: 'line',
  193. smooth: true,
  194. animationDuration: 1000,
  195. symbolSize: 10,
  196. data: dataY3.value,
  197. },
  198. ],
  199. });
  200. watchEffect(() => {
  201. if (props.chartData && props.chartData.dqPa && props.chartData.fanM3) {
  202. getEchartsData();
  203. option.series[0].data = dataY1.value;
  204. option.series[1].data = dataY2.value;
  205. option.series[2].data = dataY3.value;
  206. setOptions(option, false);
  207. }
  208. });
  209. function getEchartsData(param = { dataA: -0.056, dataB: 3.6491, dataC: 4364.4, dataQ: 205.97, dataH: 2740.6 }) {
  210. const Q1 = props.chartData.fanM3;
  211. const H1 = props.chartData.dqPa;
  212. const q = Q1 - param.dataQ;
  213. const h = H1 - param.dataH;
  214. dataY1.value = [];
  215. dataY2.value = [];
  216. dataY3.value = [];
  217. for (let i = 0; i <= 400; i++) {
  218. const x = i;
  219. const y = (H1 / Q1 / Q1) * x * x;
  220. dataY1.value.push([x, y]);
  221. if (i >= 30) {
  222. const y4 = param.dataA * (x - q) * (x - q) + param.dataB * (x - q) + param.dataC + h;
  223. dataY2.value.push([x, y4]);
  224. }
  225. }
  226. dataY3.value.push([Q1, H1]);
  227. // dispatchAction(Q1)
  228. }
  229. // const dispatchAction = (dataIndex) => {
  230. // getInstance()
  231. // }
  232. onMounted(() => {
  233. setOptions(option, false);
  234. });
  235. return { chartRef };
  236. },
  237. });
  238. </script>
  239. <style></style>