scatter-line-chart.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  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. props: {
  10. width: {
  11. type: String,
  12. default: "100%",
  13. },
  14. height: {
  15. type: String,
  16. default: "350px",
  17. },
  18. // 传入数据
  19. data: {
  20. type: Array,
  21. default: () => [
  22. {
  23. title: "男",
  24. value: [
  25. [161.2, 51.6],
  26. [167.5, 59.0],
  27. [159.5, 49.2],
  28. [157.0, 63.0],
  29. [155.8, 53.6],
  30. [170.0, 59.0],
  31. [159.1, 47.6],
  32. [166.0, 69.8],
  33. [176.2, 66.8],
  34. [160.2, 75.2],
  35. [172.5, 55.2],
  36. [170.9, 54.2],
  37. [172.9, 62.5],
  38. [153.4, 42.0],
  39. [160.0, 50.0],
  40. [147.2, 49.8],
  41. [168.2, 49.2],
  42. [175.0, 73.2],
  43. [157.0, 47.8],
  44. [167.6, 68.8],
  45. [159.5, 50.6],
  46. [175.0, 82.5],
  47. [166.8, 57.2],
  48. [176.5, 87.8],
  49. [170.2, 72.8],
  50. [174.0, 54.5],
  51. [173.0, 59.8],
  52. [179.9, 67.3],
  53. [170.5, 67.8],
  54. [160.0, 47.0],
  55. [154.4, 46.2],
  56. [162.0, 55.0],
  57. [176.5, 83.0],
  58. [160.0, 54.4],
  59. [152.0, 45.8],
  60. [162.1, 53.6],
  61. [170.0, 73.2],
  62. [160.2, 52.1],
  63. [161.3, 67.9],
  64. [166.4, 56.6],
  65. [168.9, 62.3],
  66. [163.8, 58.5],
  67. [167.6, 54.5],
  68. [160.0, 50.2],
  69. [161.3, 60.3],
  70. [167.6, 58.3],
  71. [165.1, 56.2],
  72. [160.0, 50.2],
  73. [170.0, 72.9],
  74. [157.5, 59.8],
  75. [167.6, 61.0],
  76. [160.7, 69.1],
  77. [163.2, 55.9],
  78. [152.4, 46.5],
  79. [157.5, 54.3],
  80. [168.3, 54.8],
  81. [180.3, 60.7],
  82. [165.5, 60.0],
  83. [165.0, 62.0],
  84. [164.5, 60.3],
  85. [156.0, 52.7],
  86. [160.0, 74.3],
  87. [163.0, 62.0],
  88. [165.7, 73.1],
  89. [161.0, 80.0],
  90. [162.0, 54.7],
  91. [166.0, 53.2],
  92. [174.0, 75.7],
  93. [172.7, 61.1],
  94. [167.6, 55.7],
  95. [151.1, 48.7],
  96. [164.5, 52.3],
  97. [163.5, 50.0],
  98. [152.0, 59.3],
  99. [169.0, 62.5],
  100. [164.0, 55.7],
  101. [161.2, 54.8],
  102. [155.0, 45.9],
  103. [170.0, 70.6],
  104. [176.2, 67.2],
  105. [170.0, 69.4],
  106. [162.5, 58.2],
  107. [170.3, 64.8],
  108. [164.1, 71.6],
  109. [169.5, 52.8],
  110. [163.2, 59.8],
  111. [154.5, 49.0],
  112. [159.8, 50.0],
  113. [173.2, 69.2],
  114. [170.0, 55.9],
  115. [161.4, 63.4],
  116. [169.0, 58.2],
  117. [166.2, 58.6],
  118. [159.4, 45.7],
  119. [162.5, 52.2],
  120. [159.0, 48.6],
  121. [162.8, 57.8],
  122. [159.0, 55.6],
  123. [179.8, 66.8],
  124. [162.9, 59.4],
  125. [161.0, 53.6],
  126. [151.1, 73.2],
  127. [168.2, 53.4],
  128. [168.9, 69.0],
  129. [173.2, 58.4],
  130. [171.8, 56.2],
  131. [178.0, 70.6],
  132. [164.3, 59.8],
  133. [163.0, 72.0],
  134. [168.5, 65.2],
  135. [166.8, 56.6],
  136. [172.7, 105.2],
  137. [163.5, 51.8],
  138. [169.4, 63.4],
  139. [167.8, 59.0],
  140. [159.5, 47.6],
  141. [167.6, 63.0],
  142. [161.2, 55.2],
  143. [160.0, 45.0],
  144. [163.2, 54.0],
  145. [162.2, 50.2],
  146. [161.3, 60.2],
  147. [149.5, 44.8],
  148. [157.5, 58.8],
  149. [163.2, 56.4],
  150. [172.7, 62.0],
  151. [155.0, 49.2],
  152. [156.5, 67.2],
  153. [164.0, 53.8],
  154. [160.9, 54.4],
  155. [162.8, 58.0],
  156. [167.0, 59.8],
  157. [160.0, 54.8],
  158. [160.0, 43.2],
  159. [168.9, 60.5],
  160. [158.2, 46.4],
  161. [156.0, 64.4],
  162. [160.0, 48.8],
  163. [167.1, 62.2],
  164. [158.0, 55.5],
  165. [167.6, 57.8],
  166. [156.0, 54.6],
  167. [162.1, 59.2],
  168. [173.4, 52.7],
  169. [159.8, 53.2],
  170. [170.5, 64.5],
  171. [159.2, 51.8],
  172. [157.5, 56.0],
  173. [161.3, 63.6],
  174. [162.6, 63.2],
  175. [160.0, 59.5],
  176. [168.9, 56.8],
  177. [165.1, 64.1],
  178. [162.6, 50.0],
  179. [165.1, 72.3],
  180. [166.4, 55.0],
  181. [160.0, 55.9],
  182. [152.4, 60.4],
  183. [170.2, 69.1],
  184. [162.6, 84.5],
  185. [170.2, 55.9],
  186. [158.8, 55.5],
  187. [172.7, 69.5],
  188. [167.6, 76.4],
  189. [162.6, 61.4],
  190. [167.6, 65.9],
  191. [156.2, 58.6],
  192. [175.2, 66.8],
  193. [172.1, 56.6],
  194. [162.6, 58.6],
  195. [160.0, 55.9],
  196. [165.1, 59.1],
  197. [182.9, 81.8],
  198. [166.4, 70.7],
  199. [165.1, 56.8],
  200. [177.8, 60.0],
  201. [165.1, 58.2],
  202. [175.3, 72.7],
  203. [154.9, 54.1],
  204. [158.8, 49.1],
  205. [172.7, 75.9],
  206. [168.9, 55.0],
  207. [161.3, 57.3],
  208. [167.6, 55.0],
  209. [165.1, 65.5],
  210. [175.3, 65.5],
  211. [157.5, 48.6],
  212. [163.8, 58.6],
  213. [167.6, 63.6],
  214. [165.1, 55.2],
  215. [165.1, 62.7],
  216. [168.9, 56.6],
  217. [162.6, 53.9],
  218. [164.5, 63.2],
  219. [176.5, 73.6],
  220. [168.9, 62.0],
  221. [175.3, 63.6],
  222. [159.4, 53.2],
  223. [160.0, 53.4],
  224. [170.2, 55.0],
  225. [162.6, 70.5],
  226. [167.6, 54.5],
  227. [162.6, 54.5],
  228. [160.7, 55.9],
  229. [160.0, 59.0],
  230. [157.5, 63.6],
  231. [162.6, 54.5],
  232. [152.4, 47.3],
  233. [170.2, 67.7],
  234. [165.1, 80.9],
  235. [172.7, 70.5],
  236. [165.1, 60.9],
  237. [170.2, 63.6],
  238. [170.2, 54.5],
  239. [170.2, 59.1],
  240. [161.3, 70.5],
  241. [167.6, 52.7],
  242. [167.6, 62.7],
  243. [165.1, 86.3],
  244. [162.6, 66.4],
  245. [152.4, 67.3],
  246. [168.9, 63.0],
  247. [170.2, 73.6],
  248. [175.2, 62.3],
  249. [175.2, 57.7],
  250. [160.0, 55.4],
  251. [165.1, 104.1],
  252. [174.0, 55.5],
  253. [170.2, 77.3],
  254. [160.0, 80.5],
  255. [167.6, 64.5],
  256. [167.6, 72.3],
  257. [167.6, 61.4],
  258. [154.9, 58.2],
  259. [162.6, 81.8],
  260. [175.3, 63.6],
  261. [171.4, 53.4],
  262. [157.5, 54.5],
  263. [165.1, 53.6],
  264. [160.0, 60.0],
  265. [174.0, 73.6],
  266. [162.6, 61.4],
  267. [174.0, 55.5],
  268. [162.6, 63.6],
  269. [161.3, 60.9],
  270. [156.2, 60.0],
  271. [149.9, 46.8],
  272. [169.5, 57.3],
  273. [160.0, 64.1],
  274. [175.3, 63.6],
  275. [169.5, 67.3],
  276. [160.0, 75.5],
  277. [172.7, 68.2],
  278. [162.6, 61.4],
  279. [157.5, 76.8],
  280. [176.5, 71.8],
  281. [164.4, 55.5],
  282. [160.7, 48.6],
  283. [174.0, 66.4],
  284. [163.8, 67.3],
  285. ],
  286. },
  287. {
  288. title: "女",
  289. value: [
  290. [174.0, 65.6],
  291. [175.3, 71.8],
  292. [193.5, 80.7],
  293. [186.5, 72.6],
  294. [187.2, 78.8],
  295. [181.5, 74.8],
  296. [184.0, 86.4],
  297. [184.5, 78.4],
  298. [175.0, 62.0],
  299. [184.0, 81.6],
  300. [180.0, 76.6],
  301. [177.8, 83.6],
  302. [192.0, 90.0],
  303. [176.0, 74.6],
  304. [174.0, 71.0],
  305. [184.0, 79.6],
  306. [192.7, 93.8],
  307. [171.5, 70.0],
  308. [173.0, 72.4],
  309. [176.0, 85.9],
  310. [176.0, 78.8],
  311. [180.5, 77.8],
  312. [172.7, 66.2],
  313. [176.0, 86.4],
  314. [173.5, 81.8],
  315. [178.0, 89.6],
  316. [180.3, 82.8],
  317. [180.3, 76.4],
  318. [164.5, 63.2],
  319. [173.0, 60.9],
  320. [183.5, 74.8],
  321. [175.5, 70.0],
  322. [188.0, 72.4],
  323. [189.2, 84.1],
  324. [172.8, 69.1],
  325. [170.0, 59.5],
  326. [182.0, 67.2],
  327. [170.0, 61.3],
  328. [177.8, 68.6],
  329. [184.2, 80.1],
  330. [186.7, 87.8],
  331. [171.4, 84.7],
  332. [172.7, 73.4],
  333. [175.3, 72.1],
  334. [180.3, 82.6],
  335. [182.9, 88.7],
  336. [188.0, 84.1],
  337. [177.2, 94.1],
  338. [172.1, 74.9],
  339. [167.0, 59.1],
  340. [169.5, 75.6],
  341. [174.0, 86.2],
  342. [172.7, 75.3],
  343. [182.2, 87.1],
  344. [164.1, 55.2],
  345. [163.0, 57.0],
  346. [171.5, 61.4],
  347. [184.2, 76.8],
  348. [174.0, 86.8],
  349. [174.0, 72.2],
  350. [177.0, 71.6],
  351. [186.0, 84.8],
  352. [167.0, 68.2],
  353. [171.8, 66.1],
  354. [182.0, 72.0],
  355. [167.0, 64.6],
  356. [177.8, 74.8],
  357. [164.5, 70.0],
  358. [192.0, 101.6],
  359. [175.5, 63.2],
  360. [171.2, 79.1],
  361. [181.6, 78.9],
  362. [167.4, 67.7],
  363. [181.1, 66.0],
  364. [177.0, 68.2],
  365. [174.5, 63.9],
  366. [177.5, 72.0],
  367. [170.5, 56.8],
  368. [182.4, 74.5],
  369. [197.1, 90.9],
  370. [180.1, 93.0],
  371. [175.5, 80.9],
  372. [180.6, 72.7],
  373. [184.4, 68.0],
  374. [175.5, 70.9],
  375. [180.6, 72.5],
  376. [177.0, 72.5],
  377. [177.1, 83.4],
  378. [181.6, 75.5],
  379. [176.5, 73.0],
  380. [175.0, 70.2],
  381. [174.0, 73.4],
  382. [165.1, 70.5],
  383. [177.0, 68.9],
  384. [192.0, 102.3],
  385. [176.5, 68.4],
  386. [169.4, 65.9],
  387. [182.1, 75.7],
  388. [179.8, 84.5],
  389. [175.3, 87.7],
  390. [184.9, 86.4],
  391. [177.3, 73.2],
  392. [167.4, 53.9],
  393. [178.1, 72.0],
  394. [168.9, 55.5],
  395. [157.2, 58.4],
  396. [180.3, 83.2],
  397. [170.2, 72.7],
  398. [177.8, 64.1],
  399. [172.7, 72.3],
  400. [165.1, 65.0],
  401. [186.7, 86.4],
  402. [165.1, 65.0],
  403. [174.0, 88.6],
  404. [175.3, 84.1],
  405. [185.4, 66.8],
  406. [177.8, 75.5],
  407. [180.3, 93.2],
  408. [180.3, 82.7],
  409. [177.8, 58.0],
  410. [177.8, 79.5],
  411. [177.8, 78.6],
  412. [177.8, 71.8],
  413. [177.8, 116.4],
  414. [163.8, 72.2],
  415. [188.0, 83.6],
  416. [198.1, 85.5],
  417. [175.3, 90.9],
  418. [166.4, 85.9],
  419. [190.5, 89.1],
  420. [166.4, 75.0],
  421. [177.8, 77.7],
  422. [179.7, 86.4],
  423. [172.7, 90.9],
  424. [190.5, 73.6],
  425. [185.4, 76.4],
  426. [168.9, 69.1],
  427. [167.6, 84.5],
  428. [175.3, 64.5],
  429. [170.2, 69.1],
  430. [190.5, 108.6],
  431. [177.8, 86.4],
  432. [190.5, 80.9],
  433. [177.8, 87.7],
  434. [184.2, 94.5],
  435. [176.5, 80.2],
  436. [177.8, 72.0],
  437. [180.3, 71.4],
  438. [171.4, 72.7],
  439. [172.7, 84.1],
  440. [172.7, 76.8],
  441. [177.8, 63.6],
  442. [177.8, 80.9],
  443. [182.9, 80.9],
  444. [170.2, 85.5],
  445. [167.6, 68.6],
  446. [175.3, 67.7],
  447. [165.1, 66.4],
  448. [185.4, 102.3],
  449. [181.6, 70.5],
  450. [172.7, 95.9],
  451. [190.5, 84.1],
  452. [179.1, 87.3],
  453. [175.3, 71.8],
  454. [170.2, 65.9],
  455. [193.0, 95.9],
  456. [171.4, 91.4],
  457. [177.8, 81.8],
  458. [177.8, 96.8],
  459. [167.6, 69.1],
  460. [167.6, 82.7],
  461. [180.3, 75.5],
  462. [182.9, 79.5],
  463. [176.5, 73.6],
  464. [186.7, 91.8],
  465. [188.0, 84.1],
  466. [188.0, 85.9],
  467. [177.8, 81.8],
  468. [174.0, 82.5],
  469. [177.8, 80.5],
  470. [171.4, 70.0],
  471. [185.4, 81.8],
  472. [185.4, 84.1],
  473. [188.0, 90.5],
  474. [188.0, 91.4],
  475. [182.9, 89.1],
  476. [176.5, 85.0],
  477. [175.3, 69.1],
  478. [175.3, 73.6],
  479. [188.0, 80.5],
  480. [188.0, 82.7],
  481. [175.3, 86.4],
  482. [170.5, 67.7],
  483. [179.1, 92.7],
  484. [177.8, 93.6],
  485. [175.3, 70.9],
  486. [182.9, 75.0],
  487. [170.8, 93.2],
  488. [188.0, 93.2],
  489. [180.3, 77.7],
  490. [177.8, 61.4],
  491. [185.4, 94.1],
  492. [168.9, 75.0],
  493. [185.4, 83.6],
  494. [180.3, 85.5],
  495. [174.0, 73.9],
  496. [167.6, 66.8],
  497. [182.9, 87.3],
  498. [160.0, 72.3],
  499. [180.3, 88.6],
  500. [167.6, 75.5],
  501. [186.7, 101.4],
  502. [175.3, 91.1],
  503. [175.3, 67.3],
  504. [175.9, 77.7],
  505. [175.3, 81.8],
  506. [179.1, 75.5],
  507. [181.6, 84.5],
  508. [177.8, 76.6],
  509. [182.9, 85.0],
  510. [177.8, 102.5],
  511. [184.2, 77.3],
  512. [179.1, 71.8],
  513. [176.5, 87.9],
  514. [188.0, 94.3],
  515. [174.0, 70.9],
  516. [167.6, 64.5],
  517. [170.2, 77.3],
  518. [167.6, 72.3],
  519. [188.0, 87.3],
  520. [174.0, 80.0],
  521. [176.5, 82.3],
  522. [180.3, 73.6],
  523. [167.6, 74.1],
  524. [188.0, 85.9],
  525. [180.3, 73.2],
  526. [167.6, 76.3],
  527. [183.0, 65.9],
  528. [183.0, 90.9],
  529. [179.1, 89.1],
  530. [170.2, 62.3],
  531. [177.8, 82.7],
  532. [179.1, 79.1],
  533. [190.5, 98.2],
  534. [177.8, 84.1],
  535. [180.3, 83.2],
  536. [180.3, 83.2],
  537. ],
  538. },
  539. ],
  540. },
  541. xTitle: {
  542. type: String,
  543. default: "x轴标题",
  544. },
  545. yTitle: {
  546. type: String,
  547. default: "Y轴标题",
  548. },
  549. showLegend: {
  550. type: Boolean,
  551. default: true,
  552. },
  553. lineData: {
  554. type: Object,
  555. default: () => {
  556. return {
  557. xTitle: "折线X",
  558. yTitle: "折线y",
  559. legends: ["1", "2", "3"],
  560. data: [[1, 2, 3, 4]],
  561. };
  562. },
  563. },
  564. },
  565. data() {
  566. return {
  567. id: "",
  568. chart: null,
  569. color: ["#05bb4c", "#f8de5b", "#4b55ae", "#fa8c16"],
  570. };
  571. },
  572. computed: {
  573. series() {
  574. let result = [];
  575. this.data.forEach((element, index) => {
  576. result.push({
  577. name: element.title,
  578. type: "scatter",
  579. emphasis: {
  580. focus: "series",
  581. },
  582. data: element.value,
  583. markLine: {
  584. data: [
  585. {
  586. type: "max",
  587. name: "最大值",
  588. label: {
  589. color: this.$store.state.themeName === "dark" ? partten.getColor("gray") : "#000",
  590. },
  591. },
  592. {
  593. type: "min",
  594. name: "最小值",
  595. label: {
  596. color: this.$store.state.themeName === "dark" ? partten.getColor("gray") : "#000",
  597. },
  598. },
  599. ],
  600. },
  601. });
  602. });
  603. return result;
  604. },
  605. legend() {
  606. let result = [];
  607. // if (this.data && this.data.length > 0)
  608. // result.push(
  609. // this.data.map((t) => {
  610. // return t.title;
  611. // })
  612. // );
  613. // if (this.lineData && this.lineData.legends && this.lineData.legends.legends > 0) result.push(this.lineData.legends);
  614. this.data.forEach((ele) => {
  615. result.push(ele.title);
  616. });
  617. this.lineData.legends.forEach((ele) => {
  618. result.push(ele);
  619. });
  620. return result;
  621. },
  622. },
  623. methods: {
  624. resize() {},
  625. initChart() {
  626. let that = this;
  627. const chart = echarts.init(this.$el);
  628. let option = {
  629. color: this.color,
  630. grid: {
  631. top: 40,
  632. left: 40,
  633. right: 64,
  634. bottom: 24,
  635. containLabel: true,
  636. },
  637. tooltip: {
  638. trigger: "item",
  639. showDelay: 0,
  640. backgroundColor: this.$store.state.themeName === "dark" ? "rgba(0,0,0,0.4)" : "rgba(255,255,255,0.5)",
  641. borderColor: this.$store.state.themeName === "dark" ? partten.getColor("gray") : "#000",
  642. textStyle: {
  643. fontSize: util.vh(16),
  644. color: this.$store.state.themeName === "dark" ? "#fff" : "#000",
  645. },
  646. formatter(params) {
  647. if (params.componentType == "markLine") {
  648. return params.name + "<br />" + params.value;
  649. }
  650. var msg = params.seriesName + "<br />";
  651. msg +=
  652. params.marker + that.xTitle + ":" + params.value[0] + "<br />";
  653. msg +=
  654. params.marker + that.yTitle + ":" + params.value[1] + "<br />";
  655. return msg;
  656. },
  657. axisPointer: {
  658. show: true,
  659. type: "cross",
  660. lineStyle: {
  661. type: "dashed",
  662. width: 1,
  663. },
  664. },
  665. },
  666. legend: {
  667. show: this.showLegend,
  668. data: this.legend,
  669. right: "40",
  670. icon: "circle",
  671. itemWidth: 6,
  672. inactiveColor: this.$store.state.themeName === "dark" ? partten.getColor("gray") : "#000",
  673. textStyle: {
  674. color: this.$store.state.themeName === "dark" ? partten.getColor("grayl") : "#000",
  675. fontSize: 12,
  676. },
  677. },
  678. xAxis: [
  679. {
  680. name: this.xTitle,
  681. type: "value",
  682. scale: true,
  683. axisLabel: {
  684. formatter: "{value}",
  685. },
  686. splitLine: {
  687. show: false,
  688. },
  689. },
  690. ],
  691. yAxis: [
  692. {
  693. min: 0,
  694. type: "value",
  695. name: this.yTitle,
  696. scale: true,
  697. axisLabel: {
  698. formatter: "{value}",
  699. },
  700. splitLine: {
  701. show: false,
  702. },
  703. },
  704. ],
  705. series: this.series,
  706. };
  707. if (this.lineData && this.lineData.data) {
  708. option.xAxis.push({
  709. type: "category",
  710. // name: this.lineData.xTitle,
  711. boundaryGap: false,
  712. axisLabel: {
  713. show: false,
  714. },
  715. axisLine: {
  716. show: false,
  717. },
  718. data: this.lineData.legends,
  719. });
  720. option.yAxis.push({
  721. type: "value",
  722. // name: this.lineData.yTitle,
  723. axisLabel: {
  724. show: false,
  725. },
  726. axisLine: {
  727. show: false,
  728. },
  729. //分格线
  730. splitLine: {
  731. show: false,
  732. },
  733. });
  734. this.lineData.data.forEach((value, index) => {
  735. option.series.push({
  736. name: this.lineData.legends[index],
  737. type: "line",
  738. smooth: true,
  739. showSymbol: false,
  740. zlevel: index,
  741. lineStyle: {
  742. show: false,
  743. },
  744. yAxisIndex: 0,
  745. xAxisIndex: 1,
  746. data: value,
  747. });
  748. });
  749. }
  750. chart.clear();
  751. chart.setOption(option);
  752. this.resize = function () {
  753. chart.resize();
  754. };
  755. window.addEventListener("resize", this.resize);
  756. },
  757. },
  758. created() {
  759. this.id = "pie-chart-" + util.newGUID();
  760. },
  761. mounted() {
  762. this.$nextTick(() => {
  763. this.$el.style.width = this.width;
  764. this.$el.style.height = this.height;
  765. this.initChart();
  766. });
  767. },
  768. updated() {
  769. this.$nextTick(() => {
  770. this.initChart();
  771. });
  772. },
  773. unmounted() {
  774. window.removeEventListener("resize", this.resize);
  775. },
  776. watch: {
  777. "$store.state.themeName"() {
  778. this.initChart();
  779. },
  780. },
  781. };
  782. </script>
  783. <style lang="less">
  784. .chart {
  785. width: 100%;
  786. height: 100%;
  787. display: inline-block;
  788. }
  789. </style>