report_line.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <!-- -->
  2. <template>
  3. <div class="chart-template chart-template-withperiod">
  4. <p>
  5. <span> {{ title }} </span>
  6. </p>
  7. <div>
  8. <el-tabs v-model="activeName" @tab-click="handleClick">
  9. <el-tab-pane
  10. v-for="t in types"
  11. :key="t.value"
  12. :label="t.text"
  13. :name="t.value"
  14. ></el-tab-pane>
  15. </el-tabs>
  16. </div>
  17. <div ref="chart"></div>
  18. </div>
  19. </template>
  20. <script>
  21. import "./../../board.scss";
  22. import * as echarts from "echarts";
  23. import {
  24. findMaxIndex,
  25. getChartDOMSize,
  26. getNextPeriod,
  27. getPeriodText,
  28. } from "../../utils.js";
  29. const types = [
  30. {
  31. text: "近7天",
  32. value: "1",
  33. },
  34. {
  35. text: "近七周",
  36. value: "2",
  37. },
  38. {
  39. text: "近七月",
  40. value: "3",
  41. },
  42. ];
  43. export default {
  44. props: {
  45. orgId: {
  46. type: String,
  47. isRequired: true,
  48. },
  49. title: {
  50. type: String,
  51. isRequired: true,
  52. },
  53. },
  54. data() {
  55. return {
  56. data: {
  57. all: [],
  58. completed: [],
  59. name: [],
  60. },
  61. activeName: types[0].value,
  62. };
  63. },
  64. components: {},
  65. computed: {},
  66. watch: {
  67. orgId: {
  68. deep: true,
  69. handler(val) {
  70. this.resetTimer();
  71. this.getData();
  72. },
  73. },
  74. data: {
  75. deep: true,
  76. handler() {
  77. this.initMap();
  78. },
  79. },
  80. },
  81. created() {
  82. this.types = types;
  83. this.maxDisplay = 16;
  84. this.refreshTime = 1 * 10 * 1000;
  85. this.isMouseOver = false;
  86. },
  87. async mounted() {
  88. window.addEventListener("resize", this.windowResize);
  89. },
  90. beforeDestroy() {
  91. this.timer && clearInterval(this.timer);
  92. this.timer = null;
  93. window.removeEventListener("resize", this.windowResize);
  94. },
  95. methods: {
  96. handleClick() {
  97. this.resetTimer();
  98. this.getData();
  99. },
  100. handleMouseEnter() {
  101. this.isMouseOver = true;
  102. },
  103. handleMouseLeave() {
  104. this.isMouseOver = false;
  105. },
  106. async getData() {
  107. let bs = parseInt(this.activeName) + 1;
  108. this.data = {
  109. all: [
  110. 210 * bs,
  111. 101 * bs,
  112. 117 * bs,
  113. 78 * bs,
  114. 107 * bs,
  115. 105 * bs,
  116. 124 * bs,
  117. ],
  118. completed: [
  119. 155 * bs,
  120. 99 * bs,
  121. 110 * bs,
  122. 78 * bs,
  123. 104 * bs,
  124. 102 * bs,
  125. 115 * bs,
  126. ],
  127. name: ["10.25", "10.24", "10-23", "10-22", "10-21", "10-20", "10-19"],
  128. };
  129. this.data.rate = [];
  130. this.data.all.forEach((v, i) => {
  131. this.data.rate[i] = (this.data.completed[i] / this.data.all[i]) * 100;
  132. });
  133. console.info(this.data);
  134. },
  135. windowResize() {
  136. this.myChart && this.myChart.resize();
  137. },
  138. initMap() {
  139. this.myChart && this.myChart.dispose();
  140. let chart = this.$refs["chart"];
  141. // 基于准备好的dom,初始化echarts实例
  142. this.myChart = echarts.init(
  143. chart
  144. // document.getElementById("commAlarmEvent_Chart")
  145. );
  146. let t = this;
  147. // 指定图表的配置项和数据
  148. var option = {
  149. color: ["rgb(250,200,88)"],
  150. tooltip: {
  151. trigger: "axis",
  152. confine: true,
  153. axisPointer: {
  154. type: "shadow",
  155. },
  156. formatter: "{c}%",
  157. },
  158. legend: {
  159. show: true,
  160. textStyle: {
  161. color: "rgb(245, 245, 245)",
  162. },
  163. },
  164. grid: {
  165. left: "3%",
  166. right: "4%",
  167. bottom: "2%",
  168. top: "40px",
  169. containLabel: true,
  170. },
  171. xAxis: [
  172. {
  173. type: "category",
  174. data: this.data.name,
  175. // data: this.mapdata.totalDataVo.xlist,
  176. axisTick: {
  177. alignWithLabel: true,
  178. },
  179. axisLine: {
  180. show: true,
  181. lineStyle: {
  182. type: "solid",
  183. color: "rgb(245, 245, 245)", //左边线的颜⾊
  184. },
  185. },
  186. axisLabel: {
  187. interval: 0,
  188. rotate: -30,
  189. fontSize: 12,
  190. // color: "#fff",
  191. },
  192. },
  193. ],
  194. yAxis: [
  195. {
  196. type: "value",
  197. minInterval: 1,
  198. min:Math.min(...this.data.rate,50),
  199. max:100,
  200. // max: function (value) {
  201. // let m = value.max == Math.ceil(value.max) ? Math.ceil(value.max * 1.0001) : Math.ceil(value.max);
  202. // return m
  203. // },
  204. },
  205. ],
  206. series: [
  207. // {
  208. // name: "总数",
  209. // type: "bar",
  210. // barWidth: "14",
  211. // // label: {
  212. // // show: true,
  213. // // position: 'top',
  214. // // },
  215. // data: this.data.all,
  216. // },
  217. {
  218. name: "完成率",
  219. type: "line",
  220. barWidth: "14",
  221. // label: {
  222. // show: true,
  223. // position: 'top',
  224. // },
  225. data: this.data.rate,
  226. itemStyle: {
  227. normal: {
  228. label: {
  229. formatter: function (param) {
  230. // if (t.data.all[param.dataIndex]) {
  231. // let rate = param.value / t.data.all[param.dataIndex];
  232. // return (Math.floor(rate * 1000) / 10).toFixed(1) + "%";
  233. // } else {
  234. // return "";
  235. // }
  236. return param.value.toFixed(1) + "%";
  237. },
  238. show: true,
  239. position: "top",
  240. textStyle: {
  241. fontWeight: "bolder",
  242. fontSize: "12",
  243. color: "rgb(245, 245, 245)",
  244. },
  245. },
  246. },
  247. },
  248. },
  249. ],
  250. };
  251. if (option && typeof option === "object") {
  252. this.myChart.setOption(option);
  253. }
  254. },
  255. resetTimer() {
  256. this.timer && clearInterval(this.timer);
  257. this.timer = setInterval(() => {
  258. if (this.isMouseOver) {
  259. return;
  260. }
  261. this.activeName = getNextPeriod(this.types, this.activeName);
  262. this.getData();
  263. }, this.refreshTime);
  264. },
  265. },
  266. };
  267. </script>
  268. <style lang="less" scoped></style>