electricChart.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. // backgroundColor: "pink",
  24. color: ["#f2e251", "#48C964", "#fe8161"],
  25. legend: {
  26. bottom: "0",
  27. data: ["A相电流", "B相电流", "C相电流"],
  28. },
  29. // toolbox: {
  30. // show: false,
  31. // },
  32. tooltip: {
  33. // show: true
  34. trigger: "axis",
  35. axisPointer: { type: "cross" },
  36. },
  37. grid: {
  38. left: "20",
  39. right: "40",
  40. top: "40",
  41. bottom: "30",
  42. containLabel: true,
  43. },
  44. xAxis: {
  45. axisLabel: {
  46. color: "#444", fontSize: 14 ,
  47. },
  48. /*改变xy轴颜色*/
  49. axisLine: {
  50. lineStyle: {
  51. color: "#444",
  52. width: 1, //这里是为了突出显示加上的
  53. },
  54. },
  55. boundaryGap: false,
  56. data: ["0:00", "2:00", "4:00", "6:00", "8:00","10:00","12:00","14:00","16:00","18:00","20:00","22:00","24:00",],
  57. },
  58. yAxis: {
  59. name: "A",
  60. nameTextStyle: {
  61. color: "#707070",
  62. fontSize: 14,
  63. },
  64. axisLabel: {
  65. color: "#444", fontSize: 14 ,
  66. },
  67. axisLine: {
  68. symbolOffset: [0, 4],
  69. lineStyle: { color: "#444" },
  70. },
  71. splitArea: {
  72. show: false,
  73. },
  74. },
  75. series: [
  76. {
  77. name: "A相电流",
  78. type: "line",
  79. symbolSize: 7,
  80. smooth: false,
  81. data: [10, 2, 12, 0, 5,10, 2, 12, 0, 5,10, 2, 12, 0, 5,10, 2, 12, 0, 5,10, 2, 12, 0, 5,],
  82. },
  83. {
  84. name: "B相电流",
  85. type: "line",
  86. symbolSize: 7,
  87. smooth: false,
  88. data: [10, 2, 12, 0,7, 8, 9, 7, 19,7, 8, 9, 7, 19,7, 8, 9, 7, 19,7, 8, 9, 7, 19,7, 8, 9, 7, 19,],
  89. },
  90. {
  91. name: "C相电流",
  92. type: "line",
  93. symbolSize: 7,
  94. smooth: false,
  95. data: [5, 3, 6, 5, 14,5, 3, 6, 5, 14,5, 3, 6, 5, 14,5, 3, 6, 5, 14,5, 3, 6, 5, 14,5, 3, 6, 5, 14],
  96. },
  97. ],
  98. };
  99. interface WorksChartCardSetupData {
  100. t: (key: string | number) => string;
  101. loading: Ref<boolean>;
  102. lineChartBanlance: Ref;
  103. total: ComputedRef<number>;
  104. num: ComputedRef<number>;
  105. }
  106. export default defineComponent({
  107. name: "ElectricChart",
  108. setup(): WorksChartCardSetupData {
  109. const store = useStore<{ Home: HomeStateType }>();
  110. const { t } = useI18n();
  111. // 总数
  112. const total = computed<number>(() => store.state.Home.worksChartData.total);
  113. // num
  114. const num = computed<number>(() => store.state.Home.worksChartData.num);
  115. // chart Data
  116. // const chartData = computed<ChartDataType>(
  117. // () => store.state.Home.worksChartData.chart
  118. // );
  119. // echarts 图表
  120. const lineChartBanlance = ref<HTMLDivElement>();
  121. const echarts = useEcharts(lineChartBanlance, worksChartOption);
  122. // watch([echarts, chartData], () => {
  123. // if (echarts.value) {
  124. // const option: EChartOption = {
  125. // xAxis: {
  126. // // data: ["03-01", "03-01", "03-01", "03-01", "03-01", "03-01", "03-01"]
  127. // data: chartData.value.day,
  128. // },
  129. // series: [
  130. // {
  131. // name: "新增",
  132. // // data: [3, 1, 1, 2, 2, 2, 2]
  133. // data: chartData.value.num,
  134. // },
  135. // ],
  136. // };
  137. // echarts.value.setOption(option);
  138. // }
  139. // });
  140. // 读取数据 func
  141. const loading = ref<boolean>(true);
  142. const getData = async () => {
  143. loading.value = true;
  144. await store.dispatch("Home/queryWorksChartData");
  145. loading.value = false;
  146. };
  147. onMounted(() => {
  148. getData();
  149. });
  150. return {
  151. t,
  152. loading,
  153. lineChartBanlance,
  154. total,
  155. num,
  156. };
  157. },
  158. });
  159. </script>
  160. <style lang="scss" scoped>
  161. .homeBoxCard {
  162. margin-bottom: 24px;
  163. ::v-deep(.el-card__header) {
  164. padding-left: 12px;
  165. padding-right: 12px;
  166. }
  167. ::v-deep(.el-card__body) {
  168. padding: 12px;
  169. font-size: 14px;
  170. line-height: 1.5715;
  171. }
  172. ::v-deep(.el-divider) {
  173. margin: 8px 0;
  174. }
  175. .num {
  176. font-size: 30px;
  177. color: #515a6e;
  178. }
  179. .height400 {
  180. height: 400px;
  181. }
  182. }
  183. </style>