chart.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. function home1Line(data, showed) {
  2. console.log(showed)
  3. return {
  4. title: {
  5. show: showed, // 是否显示title
  6. text: '暂无数据',
  7. left: 'center',
  8. top: 'center',
  9. textStyle: {
  10. color: '#9a9b9f',
  11. fontSize: 20,
  12. fontWeight: 400
  13. }
  14. },
  15. tooltip: {
  16. trigger: "axis",
  17. axisPointer: {
  18. lineStyle: {
  19. color: "#666"
  20. }
  21. },
  22. formatter(params) {
  23. var returnData = '';
  24. var time = '';
  25. for (let g in params) {
  26. time = params[g].axisValue;
  27. if (params[g].seriesIndex == 0) {
  28. returnData += params[g].seriesName + ':' + params[g].value + '%<br/>';
  29. }
  30. if (params[g].seriesIndex == 1) {
  31. returnData += params[g].seriesName + ':' + params[g].value + '°C<br/>';
  32. }
  33. }
  34. return time + '<br/>' + returnData;
  35. }
  36. },
  37. legend: {
  38. top: "10",
  39. textStyle: {
  40. color: "#666",
  41. fontSize: "12"
  42. }
  43. },
  44. grid: {
  45. left: "10",
  46. top: "80",
  47. right: "20",
  48. bottom: "10",
  49. containLabel: true
  50. },
  51. xAxis: [{
  52. type: "category",
  53. boundaryGap: false,
  54. axisLabel: {
  55. textStyle: {
  56. color: "#666",
  57. fontSize: 12
  58. }
  59. },
  60. axisLine: {
  61. lineStyle: {
  62. color: "#afb2c5"
  63. }
  64. },
  65. splitLine: {
  66. show: true,
  67. lineStyle: {
  68. color: '#afb2c5'
  69. }
  70. },
  71. data: data.time
  72. },
  73. {
  74. axisPointer: {
  75. show: false
  76. },
  77. axisLine: {
  78. show: false
  79. },
  80. position: "bottom",
  81. offset: 0
  82. }
  83. ],
  84. yAxis: [{
  85. type: "value",
  86. axisTick: {
  87. show: false
  88. },
  89. axisLine: {
  90. lineStyle: {
  91. color: "#afb2c5"
  92. }
  93. },
  94. axisLabel: {
  95. textStyle: {
  96. color: "#666",
  97. fontSize: 12
  98. }
  99. },
  100. splitLine: {
  101. show: false
  102. }
  103. }],
  104. series: [{
  105. name: "空气湿度",
  106. type: "line",
  107. smooth: true,
  108. symbol: "circle", //标记的 图形
  109. symbolSize: 5,
  110. showSymbol: true,
  111. lineStyle: {
  112. normal: {
  113. color: "#42d3ff",
  114. width: 4
  115. }
  116. },
  117. areaStyle: {
  118. normal: {
  119. color: {
  120. type: 'linear',
  121. x: 0,
  122. y: 0,
  123. x2: 0,
  124. y2: 1,
  125. colorStops: [{
  126. offset: 0,
  127. color: '#a7caff' // 0% 处的颜色
  128. }, {
  129. offset: 0.8,
  130. color: '#e3e8fe' // 100% 处的颜色
  131. }],
  132. global: false // 缺省为 false
  133. },
  134. shadowColor: "rgba(0, 0, 0, 0.1)"
  135. }
  136. },
  137. itemStyle: {
  138. normal: {
  139. color: "#62e2ff",
  140. borderColor: "#62e2ff",
  141. borderWidth: 4
  142. }
  143. },
  144. data: data.ah
  145. },
  146. {
  147. name: "空气温度",
  148. type: "line",
  149. smooth: true,
  150. symbol: "circle",
  151. symbolSize: 5,
  152. showSymbol: true,
  153. lineStyle: {
  154. normal: {
  155. color: "#fd0001",
  156. width: 3
  157. }
  158. },
  159. itemStyle: {
  160. normal: {
  161. color: "#fd0001",
  162. borderColor: "#fd0001",
  163. borderWidth: 4
  164. }
  165. },
  166. data: data.at
  167. }
  168. ]
  169. };
  170. }
  171. function home1Pie(bzy, cbd, qxz, scd, xycb, jk, tccb, xy2, wheat, sf, sycb, ndqxz) {
  172. var data = [];
  173. var colorList = [];
  174. if (bzy > 0) {
  175. data.push({
  176. "name": "孢子仪",
  177. "value": bzy
  178. })
  179. colorList.push('#00d0ae');
  180. }
  181. if (cbd > 0) {
  182. data.push({
  183. "name": "虫情测报",
  184. "value": cbd
  185. })
  186. colorList.push('#d70252');
  187. }
  188. if (qxz > 0) {
  189. data.push({
  190. "name": "环境监测",
  191. "value": qxz
  192. })
  193. colorList.push('#ffa300');
  194. }
  195. if (scd > 0) {
  196. data.push({
  197. "name": "杀虫灯",
  198. "value": scd
  199. })
  200. colorList.push('#1e75ff');
  201. }
  202. // 新
  203. if (xycb > 0) {
  204. data.push({
  205. "name": "性诱测报",
  206. "value": xycb
  207. })
  208. colorList.push('#00d0ae');
  209. }
  210. if (jk > 0) {
  211. data.push({
  212. "name": "监控",
  213. "value": jk
  214. })
  215. colorList.push('#d70252');
  216. }
  217. if (tccb > 0) {
  218. data.push({
  219. "name": "糖醋测报",
  220. "value": tccb
  221. })
  222. colorList.push('#ffa300');
  223. }
  224. if (xy2> 0) {
  225. data.push({
  226. "name": "性诱2.0",
  227. "value": xy2
  228. })
  229. colorList.push('#1e75ff');
  230. }
  231. if (wheat > 0) {
  232. data.push({
  233. "name": "小麦赤霉病",
  234. "value": wheat
  235. })
  236. colorList.push('#00d0ae');
  237. }
  238. if (sf > 0) {
  239. data.push({
  240. "name": "水肥",
  241. "value": sf
  242. })
  243. colorList.push('#d70252');
  244. }
  245. if (sycb > 0) {
  246. data.push({
  247. "name": "色诱测报",
  248. "value": sycb
  249. })
  250. colorList.push('#ffa300');
  251. }
  252. if (ndqxz> 0) {
  253. data.push({
  254. "name": "管式墒情",
  255. "value": ndqxz
  256. })
  257. colorList.push('#1e75ff');
  258. }
  259. let total = bzy + cbd + qxz + scd + xycb + jk + tccb + xy2 + wheat + sf + sycb + ndqxz
  260. return {
  261. "animation": true,
  262. "title": {
  263. "text": `${total}台`,
  264. "x": "center",
  265. "y": "center",
  266. "textStyle": {
  267. "color": "#1e74fd",
  268. "fontSize": 20,
  269. "fontWeight": "normal",
  270. "align": "center",
  271. "width": "100px",
  272. },
  273. "top": "56%",
  274. },
  275. grid: {
  276. x: '57%',
  277. y: '17%',
  278. width: '38%',
  279. height: '38%'
  280. },
  281. "legend": {
  282. "width": "90%",
  283. "left": "center",
  284. "textStyle": {
  285. "color": "#666",
  286. "fontSize": 12
  287. },
  288. "icon": "circle",
  289. "right": "0",
  290. "bottom": "0",
  291. "padding": [5, 10],
  292. "itemGap": 10,
  293. // "data": ["气象监测", "孢子仪设备", "杀虫灯设备", "测报设备"]
  294. "data": ["杀虫灯设备", "测报设备"]
  295. },
  296. "series": [{
  297. "type": "pie",
  298. // "center": ["50%", "50%"],
  299. "center": ["50%", "60%"],
  300. "radius": ['20%', "50%"],
  301. "color": colorList,
  302. "startAngle": 135,
  303. "labelLine": {
  304. "normal": {
  305. "length": 10,
  306. 'length2':5
  307. }
  308. },
  309. "label": {
  310. "normal": {
  311. "formatter": "{b|{b}\n}{per|{c}台}",
  312. "backgroundColor": "rgba(255, 147, 38, 0)",
  313. "borderColor": "red",
  314. "borderRadius": 4,
  315. "rich": {
  316. "b": {
  317. // "color": "red",
  318. "fontSize": 15,
  319. "lineHeight": 33
  320. },
  321. "per": {
  322. // "color": "#FDF44E",
  323. "fontSize": 16,
  324. "padding": [5, 6],
  325. "borderRadius": 2
  326. }
  327. },
  328. "textStyle": {
  329. "fontSize": 20
  330. }
  331. }
  332. },
  333. "emphasis": {
  334. "label": {
  335. "show": true,
  336. "formatter": "{b|{b}\n}{per|{d}%} ",
  337. "backgroundColor": "rgba(255, 147, 38, 0)",
  338. "borderColor": "transparent",
  339. "borderRadius": 4,
  340. "rich": {
  341. "a": {
  342. "color": "#999",
  343. "lineHeight": 22,
  344. "align": "center"
  345. },
  346. "b": {
  347. // "color": "red",
  348. "fontSize": 18,
  349. "lineHeight": 33
  350. },
  351. "per": {
  352. // "color": "#FDF44E",
  353. "fontSize": 18,
  354. "padding": [5, 6],
  355. "borderRadius": 2
  356. }
  357. }
  358. }
  359. },
  360. "data": data
  361. }]
  362. };
  363. }
  364. const option03 = {
  365. "animation": true,
  366. "title": {
  367. "text": '24台',
  368. "x": "center",
  369. "y": "center",
  370. "textStyle": {
  371. "color": "#1e74fd",
  372. "fontSize": 20,
  373. "fontWeight": "normal",
  374. "align": "center",
  375. "width": "100px"
  376. },
  377. },
  378. "legend": {
  379. "width": "90%",
  380. "left": "center",
  381. "textStyle": {
  382. "color": "#666",
  383. "fontSize": 12
  384. },
  385. "icon": "circle",
  386. "right": "0",
  387. "bottom": "0",
  388. "padding": [5, 10],
  389. "itemGap": 10,
  390. // "data": ["气象监测", "孢子仪设备", "杀虫灯设备", "测报设备"]
  391. "data": ["气象监测", "孢子仪设备", "杀虫灯设备", "测报设备", "性诱测报" , "监控", "糖醋测报", "性诱2.0", "小麦赤霉病", "水肥", "色诱测报", "管式墒情"]
  392. },
  393. "series": [{
  394. "type": "pie",
  395. "center": ["50%", "50%"],
  396. "radius": ["60%", "70%"],
  397. "color": ["#00d0ae", "#d70252", "#ffa300", "#1e75ff"],
  398. "startAngle": 135,
  399. "labelLine": {
  400. "normal": {
  401. "length": 25
  402. }
  403. },
  404. "label": {
  405. "normal": {
  406. "formatter": "{c}台",
  407. "backgroundColor": "rgba(255, 147, 38, 0)",
  408. "borderColor": "transparent",
  409. "borderRadius": 4,
  410. "rich": {
  411. "a": {
  412. "color": "#999",
  413. "lineHeight": 22,
  414. "align": "center"
  415. },
  416. "hr": {
  417. "borderColor": "#aaa",
  418. "width": "100%",
  419. "borderWidth": 1,
  420. "height": 0
  421. },
  422. "b": {
  423. "color": "#b3e5ff",
  424. "fontSize": 16,
  425. "lineHeight": 33
  426. },
  427. "c": {
  428. "fontSize": 90,
  429. "color": "red"
  430. },
  431. "per": {
  432. "color": "#FDF44E",
  433. "fontSize": 14,
  434. "padding": [5, 8],
  435. "borderRadius": 2
  436. }
  437. },
  438. "textStyle": {
  439. "fontSize": 20
  440. }
  441. }
  442. },
  443. "emphasis": {
  444. "label": {
  445. "show": true,
  446. "formatter": "{b|{b}:} {per|{d}%} ",
  447. "backgroundColor": "rgba(255, 147, 38, 0)",
  448. "borderColor": "transparent",
  449. "borderRadius": 4,
  450. "rich": {
  451. "a": {
  452. "color": "#999",
  453. "lineHeight": 22,
  454. "align": "center"
  455. },
  456. "hr": {
  457. "borderColor": "#aaa",
  458. "width": "100%",
  459. "borderWidth": 1,
  460. "height": 0
  461. },
  462. "b": {
  463. "color": "#fff",
  464. "fontSize": 18,
  465. "lineHeight": 33
  466. },
  467. "c": {
  468. "fontSize": 14,
  469. "color": "#eee"
  470. },
  471. "per": {
  472. "color": "#FDF44E",
  473. "fontSize": 25,
  474. "padding": [5, 6],
  475. "borderRadius": 2
  476. }
  477. }
  478. }
  479. },
  480. // "data": [{
  481. // "name": "气象监测",
  482. // "value": 3
  483. // }, {
  484. // "name": "孢子仪设备",
  485. // "value": 7
  486. // }, {
  487. // "name": "杀虫灯设备",
  488. // "value": 4
  489. // }, {
  490. // "name": "测报设备",
  491. // "value": 10
  492. // }]
  493. "data": [{
  494. "name": "气象监测",
  495. "value": 3
  496. }, {
  497. "name": "孢子仪设备",
  498. "value": 7
  499. }, {
  500. "name": "杀虫灯设备",
  501. "value": 4
  502. }, {
  503. "name": "测报设备",
  504. "value": 10
  505. },
  506. {
  507. "name": "性诱测报",
  508. "value": 3
  509. }, {
  510. "name": "监控",
  511. "value": 7
  512. }, {
  513. "name": "糖醋测报",
  514. "value": 4
  515. }, {
  516. "name": "性诱2.0",
  517. "value": 10
  518. },
  519. {
  520. "name": "小麦赤霉病",
  521. "value": 3
  522. }, {
  523. "name": "水肥",
  524. "value": 7
  525. }, {
  526. "name": "色诱测报",
  527. "value": 4
  528. }, {
  529. "name": "管式墒情",
  530. "value": 10
  531. },
  532. ]
  533. }]
  534. }
  535. // function myEcharts(arr,total) {
  536. // return {
  537. // "animation": true,
  538. // "title": {
  539. // "text": `${total}台`,
  540. // "x": "center",
  541. // "y": "center",
  542. // "textStyle": {
  543. // "color": "#1e74fd",
  544. // "fontSize": 20,
  545. // "fontWeight": "normal",
  546. // "align": "center",
  547. // "width": "100px"
  548. // },
  549. // },
  550. // "legend": {
  551. // "width": "90%",
  552. // "left": "center",
  553. // "textStyle": {
  554. // "color": "#666",
  555. // "fontSize": 12
  556. // },
  557. // "icon": "circle",
  558. // "right": "0",
  559. // "bottom": "0",
  560. // "padding": [5, 10],
  561. // "itemGap": 10,
  562. // "data": ["性诱3.0", "水电双计", "温室大棚", "水肥设备", "病虫害可视监测" , "性诱测报", "性诱2.0", "孢子仪", "环境监测", "监控设备", "水肥一体化", "小麦赤霉病","吸虫塔","玉米大斑病","测报灯","杀虫灯","管事墒情","小麦条锈病"]
  563. // },
  564. // "series": [{
  565. // "type": "pie",
  566. // "center": ["50%", "50%"],
  567. // // "radius": ["60%", "70%"],
  568. // "radius": ["30%","40%"],
  569. // "color": ["#00d0ae", "#d70252", "#ffa300", "#1e75ff"],
  570. // "startAngle": 135,
  571. // "labelLine": {
  572. // "normal": {
  573. // "length": 25
  574. // }
  575. // },
  576. // "label": {
  577. // "normal": {
  578. // "formatter": "{c}台",
  579. // "backgroundColor": "rgba(255, 147, 38, 0)",
  580. // "borderColor": "transparent",
  581. // "borderRadius": 4,
  582. // "rich": {
  583. // "a": {
  584. // "color": "#999",
  585. // "lineHeight": 22,
  586. // "align": "center"
  587. // },
  588. // "hr": {
  589. // "borderColor": "#aaa",
  590. // "width": "100%",
  591. // "borderWidth": 1,
  592. // "height": 0
  593. // },
  594. // "b": {
  595. // "color": "#b3e5ff",
  596. // "fontSize": 16,
  597. // "lineHeight": 33
  598. // },
  599. // "c": {
  600. // "fontSize": 90,
  601. // "color": "red"
  602. // },
  603. // "per": {
  604. // "color": "#FDF44E",
  605. // "fontSize": 14,
  606. // "padding": [5, 8],
  607. // "borderRadius": 2
  608. // }
  609. // },
  610. // "textStyle": {
  611. // "fontSize": 20
  612. // }
  613. // }
  614. // },
  615. // "emphasis": {
  616. // "label": {
  617. // "show": true,
  618. // "formatter": "{b|{b}:} {per|{d}%} ",
  619. // "backgroundColor": "rgba(255, 147, 38, 0)",
  620. // "borderColor": "transparent",
  621. // "borderRadius": 4,
  622. // "rich": {
  623. // "a": {
  624. // "color": "#999",
  625. // "lineHeight": 22,
  626. // "align": "center"
  627. // },
  628. // "hr": {
  629. // "borderColor": "#aaa",
  630. // "width": "100%",
  631. // "borderWidth": 1,
  632. // "height": 0
  633. // },
  634. // "b": {
  635. // "color": "#fff",
  636. // "fontSize": 18,
  637. // "lineHeight": 33
  638. // },
  639. // "c": {
  640. // "fontSize": 14,
  641. // "color": "#eee"
  642. // },
  643. // "per": {
  644. // "color": "#FDF44E",
  645. // "fontSize": 25,
  646. // "padding": [5, 6],
  647. // "borderRadius": 2
  648. // }
  649. // }
  650. // }
  651. // },
  652. // "data": arr
  653. // }]
  654. // }
  655. // }
  656. function myEcharts(arr,total) {
  657. return {
  658. title: [
  659. {
  660. // text: "标题",
  661. textStyle: {
  662. fontSize: 16,
  663. color: "black",
  664. },
  665. left: "2%",
  666. },
  667. {
  668. text: "设备数量",
  669. subtext: total,
  670. textStyle: {
  671. fontSize: 20,
  672. color: "black",
  673. },
  674. subtextStyle: {
  675. fontSize: 20,
  676. color: "black",
  677. },
  678. textAlign: "center",
  679. x: "34.5%",
  680. y: "44%",
  681. },
  682. ],
  683. tooltip: {
  684. trigger: "item",
  685. formatter: function (parms) {
  686. var str =
  687. parms.marker +
  688. "" +
  689. parms.data.name +
  690. "</br>" +
  691. "数量:" +
  692. parms.data.value +
  693. "</br>" +
  694. "占比:" +
  695. parms.percent +
  696. "%";
  697. return str;
  698. },
  699. },
  700. legend: {
  701. type: "scroll",
  702. orient: "vertical",
  703. left: "70%",
  704. align: "left",
  705. top: "middle",
  706. textStyle: {
  707. color: "#8C8C8C",
  708. },
  709. height: 250,
  710. },
  711. series: [
  712. {
  713. // name: "标题",
  714. type: "pie",
  715. center: ["35%", "50%"],
  716. radius: ["40%", "65%"],
  717. clockwise: false, //饼图的扇区是否是顺时针排布
  718. avoidLabelOverlap: false,
  719. label: {
  720. show: false
  721. },
  722. labelLine: {
  723. show: false
  724. },
  725. data: arr,
  726. },
  727. ],
  728. }
  729. }
  730. // option01和option02是Home页面的echarts数据
  731. export {
  732. home1Line,
  733. home1Pie,
  734. myEcharts,
  735. option03,
  736. }