electricChart2.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <div shadow="never" class="homeBoxCard" v-loading="loading">
  3. <div class="height400" ref="lineChartBanlance" />
  4. </div>
  5. </template>
  6. <script lang="ts">
  7. import {
  8. computed,
  9. defineComponent,
  10. onMounted,
  11. Ref,
  12. ref,
  13. watch,
  14. ComputedRef,
  15. } from "vue";
  16. import { useStore } from "vuex";
  17. import { useI18n } from "vue-i18n";
  18. import { EChartOption } from "echarts";
  19. import useEcharts from "@/composables/useEcharts";
  20. import { StateType as HomeStateType } from "../../home/store";
  21. // import { ChartDataType } from "../../data";
  22. const worksChartOption: EChartOption = {
  23. color: ["#1187FF"],
  24. legend: {
  25. bottom: "0",
  26. data: ["电流不平衡度"],
  27. },
  28. tooltip: {
  29. trigger: "axis",
  30. axisPointer: { type: "cross" },
  31. },
  32. grid: {
  33. left: "20",
  34. right: "40",
  35. top: "40",
  36. bottom: "30",
  37. containLabel: true,
  38. },
  39. xAxis: {
  40. axisLabel: {
  41. color: "#444", fontSize: 14 ,
  42. },
  43. /*改变xy轴颜色*/
  44. axisLine: {
  45. lineStyle: {
  46. color: "#444",
  47. width: 1, //这里是为了突出显示加上的
  48. },
  49. },
  50. boundaryGap: false,
  51. data: [
  52. "0:00",
  53. "2:00",
  54. "4:00",
  55. "6:00",
  56. "8:00",
  57. "10:00",
  58. "12:00",
  59. "14:00",
  60. "16:00",
  61. "18:00",
  62. "20:00",
  63. "22:00",
  64. "24:00",
  65. ],
  66. },
  67. yAxis: {
  68. name: "%",
  69. nameTextStyle: {
  70. color: "#707070",
  71. fontSize: 14,
  72. },
  73. axisLabel: {
  74. color: "#444", fontSize: 14 ,
  75. },
  76. axisLine: {
  77. symbolOffset: [0, 4],
  78. lineStyle: { color: "#444" },
  79. },
  80. splitArea: {
  81. show: false,
  82. },
  83. },
  84. series: [
  85. {
  86. name: "电流不平衡度",
  87. type: "line",
  88. symbolSize: 7,
  89. smooth: false,
  90. data: [
  91. 10, 2, 12, 0, 5, 10, 2, 12, 0, 5, 10, 2, 12, 0, 5, 10, 2, 12, 0, 5, 10,
  92. 2, 12, 0, 5,
  93. ],
  94. markLine: {
  95. //最大值和最小值
  96. data: [
  97. {
  98. yAxis: 10,
  99. label: {
  100. position: "middle",
  101. formatter: "严重三项不平衡",
  102. },
  103. lineStyle: {
  104. width: 2,
  105. color: "#FF5D1D",
  106. },
  107. },
  108. {
  109. yAxis: 8,
  110. label: {
  111. position: "middle",
  112. formatter: "不平衡度",
  113. },
  114. lineStyle: {
  115. width: 2,
  116. color: "#f2e251",
  117. },
  118. },
  119. ],
  120. },
  121. },
  122. ],
  123. };
  124. interface WorksChartCardSetupData {
  125. t: (key: string | number) => string;
  126. loading: Ref<boolean>;
  127. lineChartBanlance: Ref;
  128. total: ComputedRef<number>;
  129. num: ComputedRef<number>;
  130. }
  131. export default defineComponent({
  132. name: "ElectricChart2",
  133. setup(): WorksChartCardSetupData {
  134. const store = useStore<{ Home: HomeStateType }>();
  135. const { t } = useI18n();
  136. // 总数
  137. const total = computed<number>(() => store.state.Home.worksChartData.total);
  138. // num
  139. const num = computed<number>(() => store.state.Home.worksChartData.num);
  140. // chart Data
  141. // const chartData = computed<ChartDataType>(
  142. // () => store.state.Home.worksChartData.chart
  143. // );
  144. // echarts 图表
  145. const lineChartBanlance = ref<HTMLDivElement>();
  146. const echarts = useEcharts(lineChartBanlance, worksChartOption);
  147. // watch([echarts, chartData], () => {
  148. // if (echarts.value) {
  149. // const option: EChartOption = {
  150. // xAxis: {
  151. // // data: ["03-01", "03-01", "03-01", "03-01", "03-01", "03-01", "03-01"]
  152. // data: chartData.value.day,
  153. // },
  154. // series: [
  155. // {
  156. // name: "新增",
  157. // // data: [3, 1, 1, 2, 2, 2, 2]
  158. // data: chartData.value.num,
  159. // },
  160. // ],
  161. // };
  162. // echarts.value.setOption(option);
  163. // }
  164. // });
  165. // 读取数据 func
  166. const loading = ref<boolean>(true);
  167. const getData = async () => {
  168. loading.value = true;
  169. await store.dispatch("Home/queryWorksChartData");
  170. loading.value = false;
  171. };
  172. onMounted(() => {
  173. getData();
  174. });
  175. return {
  176. t,
  177. loading,
  178. lineChartBanlance,
  179. total,
  180. num,
  181. };
  182. },
  183. });
  184. </script>
  185. <style lang="scss" scoped>
  186. .homeBoxCard {
  187. margin-bottom: 24px;
  188. ::v-deep(.el-card__header) {
  189. padding-left: 12px;
  190. padding-right: 12px;
  191. }
  192. ::v-deep(.el-card__body) {
  193. padding: 12px;
  194. font-size: 14px;
  195. line-height: 1.5715;
  196. }
  197. ::v-deep(.el-divider) {
  198. margin: 8px 0;
  199. }
  200. .num {
  201. font-size: 30px;
  202. color: #515a6e;
  203. }
  204. .height400 {
  205. height: 400px;
  206. }
  207. }
  208. </style>