simple-line-chart.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <div class="chart" :id="id"></div>
  3. </template>
  4. <script>
  5. import util from "@/helper/util.js";
  6. import partten from "@/helper/partten.js";
  7. import * as echarts from "echarts";
  8. export default {
  9. name: "double-line-chart",
  10. componentName: "double-line-chart",
  11. props: {
  12. width: {
  13. type: String,
  14. default: "100%",
  15. },
  16. height: {
  17. type: String,
  18. default: "50px",
  19. },
  20. title: {
  21. type: String,
  22. default: "风机",
  23. },
  24. // 传入数据
  25. data: {
  26. type: Array,
  27. default: () => {
  28. return [
  29. 0,
  30. 0,
  31. 0,
  32. 0,
  33. 0,
  34. 0,
  35. 0,
  36. 1,
  37. 0,
  38. 0,
  39. 0,
  40. 0,
  41. 0,
  42. 1,
  43. 0,
  44. 0,
  45. 0,
  46. 0,
  47. 0,
  48. 0,
  49. 0,
  50. 0,
  51. 0,
  52. 0,
  53. 1,
  54. 0,
  55. 0,
  56. 0,
  57. 0,
  58. 0,
  59. 0,
  60. 0,
  61. 0,
  62. 0,
  63. 0,
  64. 0,
  65. 0,
  66. 0,
  67. 0,
  68. 0,
  69. 0,
  70. 0,
  71. 0,
  72. 0,
  73. 0,
  74. 0,
  75. 0,
  76. 0,
  77. 0,
  78. 0,
  79. 0,
  80. 0,
  81. 0,
  82. 0,
  83. 0,
  84. 0,
  85. 0,
  86. 0,
  87. 0,
  88. 0,
  89. 0,
  90. 0,
  91. 0,
  92. 0,
  93. 0,
  94. 0,
  95. 0,
  96. 0,
  97. 0,
  98. 0,
  99. 0,
  100. 0,
  101. 0,
  102. 0,
  103. 0,
  104. 0,
  105. 0,
  106. 0,
  107. 0,
  108. 0,
  109. 0,
  110. 0,
  111. 0,
  112. 0,
  113. 0,
  114. 0,
  115. 0,
  116. 0,
  117. 0,
  118. 0,
  119. 0,
  120. 0,
  121. 0,
  122. 0,
  123. 0,
  124. 0,
  125. ];
  126. },
  127. },
  128. // 单位
  129. color: {
  130. type: String,
  131. default: "green",
  132. },
  133. },
  134. data() {
  135. return {
  136. id: "",
  137. chart: null,
  138. // 时间轴
  139. xData: [
  140. "00:00",
  141. "00:15",
  142. "00:30",
  143. "00:45",
  144. "01:00",
  145. "01:15",
  146. "01:30",
  147. "01:45",
  148. "02:00",
  149. "02:15",
  150. "02:30",
  151. "02:45",
  152. "03:00",
  153. "03:15",
  154. "03:30",
  155. "03:45",
  156. "04:00",
  157. "04:15",
  158. "04:30",
  159. "04:45",
  160. "05:00",
  161. "05:15",
  162. "05:30",
  163. "05:45",
  164. "06:00",
  165. "06:15",
  166. "06:30",
  167. "06:45",
  168. "07:00",
  169. "07:15",
  170. "07:30",
  171. "07:45",
  172. "08:00",
  173. "08:15",
  174. "08:30",
  175. "08:45",
  176. "09:00",
  177. "09:15",
  178. "09:30",
  179. "09:45",
  180. "10:00",
  181. "10:15",
  182. "10:30",
  183. "10:45",
  184. "11:00",
  185. "11:15",
  186. "11:30",
  187. "11:45",
  188. "12:00",
  189. "12:15",
  190. "12:30",
  191. "12:45",
  192. "13:00",
  193. "13:15",
  194. "13:30",
  195. "13:45",
  196. "14:00",
  197. "14:15",
  198. "14:30",
  199. "14:45",
  200. "15:00",
  201. "15:15",
  202. "15:30",
  203. "15:45",
  204. "16:00",
  205. "16:15",
  206. "16:30",
  207. "16:45",
  208. "17:00",
  209. "17:15",
  210. "17:30",
  211. "17:45",
  212. "18:00",
  213. "18:15",
  214. "18:30",
  215. "18:45",
  216. "19:00",
  217. "19:15",
  218. "19:30",
  219. "19:45",
  220. "20:00",
  221. "20:15",
  222. "20:30",
  223. "20:45",
  224. "21:00",
  225. "21:15",
  226. "21:30",
  227. "21:45",
  228. "22:00",
  229. "22:15",
  230. "22:30",
  231. "22:45",
  232. "23:00",
  233. "23:15",
  234. "23:30",
  235. "23:45",
  236. ],
  237. };
  238. },
  239. computed: {
  240. colorValue() {
  241. return partten.getColor(this.color);
  242. },
  243. },
  244. methods: {
  245. resize() {},
  246. initChart() {
  247. const chart = echarts.init(this.$el);
  248. let option = {
  249. title: {
  250. text: this.title,
  251. textStyle: {
  252. color: "#ffffffcc",
  253. fontSize: 14,
  254. },
  255. left: 16,
  256. top: 0,
  257. },
  258. tooltip: {
  259. trigger: "axis",
  260. backgroundColor: "rgba(0,0,0,0.4)",
  261. textStyle: {
  262. color: "#fff",
  263. fontSize: util.vh(16),
  264. },
  265. },
  266. grid: {
  267. top: 40,
  268. left: 16,
  269. right: 16,
  270. bottom: 32,
  271. },
  272. xAxis: [
  273. {
  274. type: "category",
  275. data: this.xData,
  276. axisLine: {
  277. show: false,
  278. lineStyle: {
  279. color: partten.getColor("gray"),
  280. },
  281. },
  282. axisLabel: {
  283. show: true,
  284. margin: 16,
  285. interval: 7,
  286. },
  287. axisTick: {
  288. show: false,
  289. lineStyle: {
  290. color: partten.getColor("gray"),
  291. },
  292. },
  293. },
  294. ],
  295. yAxis: [
  296. {
  297. type: "value",
  298. splitNumber: 1,
  299. min: 0,
  300. max: 1,
  301. axisLine: {
  302. show: false,
  303. },
  304. axisLabel: {
  305. show: false,
  306. },
  307. axisTick: {
  308. show: false,
  309. },
  310. splitLine: {
  311. lineStyle: {
  312. color: partten.getColor("gray"),
  313. },
  314. },
  315. },
  316. ],
  317. series: [
  318. {
  319. type: "line",
  320. data: this.data,
  321. showAllSymbol: true,
  322. symbol: "circle",
  323. symbolSize: 10,
  324. lineStyle: {
  325. normal: {
  326. color: this.colorValue,
  327. width: 1,
  328. },
  329. },
  330. label: {
  331. show: false,
  332. },
  333. itemStyle: {
  334. color: this.colorValue,
  335. shadowColor: this.colorValue,
  336. shadowBlur: 4,
  337. },
  338. },
  339. ],
  340. };
  341. chart.clear();
  342. chart.setOption(option);
  343. this.resize = function() {
  344. chart.resize();
  345. };
  346. window.addEventListener("resize", this.resize);
  347. },
  348. },
  349. created() {
  350. this.id = "pie-chart-" + util.newGUID();
  351. },
  352. mounted() {
  353. this.$nextTick(() => {
  354. this.$el.style.width = this.width;
  355. this.$el.style.height = this.height;
  356. this.initChart();
  357. });
  358. },
  359. updated() {
  360. this.$nextTick(() => {
  361. this.initChart();
  362. });
  363. },
  364. unmounted() {
  365. window.removeEventListener("resize", this.resize);
  366. },
  367. };
  368. </script>
  369. <style lang="less">
  370. .chart {
  371. width: 100%;
  372. height: 100%;
  373. display: inline-block;
  374. }
  375. </style>