echartsTool.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. import EC from 'echarts'
  2. import eWordcloud from 'echarts-wordcloud'
  3. import { message } from 'ant-design-vue';
  4. const color = ["#00FFF0","#014EB5","#A800FF","#e82edb","#B5454C","#443bff","#e8cb25","#3dffb0","#e8a425","#ff7aab","#e84b1e","#552ce2","#ffae21","#e8861e","#d441ff","#35e8e4","#9c7aff","#e86fd8","#ffee38"];
  5. /*
  6. * 获取 自浮云 - 常用1
  7. * id: 元素ID
  8. * data: [{
  9. name: "发动机卡了", // 值
  10. value: 100, // 权重
  11. textStyle: {
  12. emphasis: {
  13. color: 'red' // 光标移入颜色
  14. }
  15. }
  16. },{
  17. name: "发动了", // 值
  18. value: 20, // 权重
  19. textStyle: {
  20. emphasis: {
  21. color: 'red' // 光标移入颜色
  22. }
  23. }
  24. }]
  25. * name: 提示框name
  26. * */
  27. export function getWordCloud(id, data) {
  28. if(data === undefined){
  29. message.error("没有找到报表数据,请检查!");
  30. return;
  31. }
  32. var myChart = EC.init(document.getElementById(id));
  33. let option = {
  34. tooltip: {},
  35. series: [{
  36. type: 'wordCloud',
  37. gridSize: 2,
  38. sizeRange: [12, 50],
  39. rotationRange: [-90, 90],
  40. shape: 'pentagon',
  41. width: 600,
  42. height: 400,
  43. drawOutOfBound: true,
  44. textStyle: {
  45. normal: {
  46. color: function() {
  47. return 'rgb(' + [
  48. Math.round(Math.random() * 160),
  49. Math.round(Math.random() * 160),
  50. Math.round(Math.random() * 160)
  51. ].join(',') + ')';
  52. }
  53. },
  54. emphasis: {
  55. shadowBlur: 10,
  56. shadowColor: '#333'
  57. }
  58. },
  59. data: data
  60. }]
  61. };
  62. myChart.setOption(option, true);
  63. }
  64. /*
  65. * 获取 雷达图 - 常用1
  66. * id: 元素ID
  67. * horn: [
  68. { name: '销售', max: 6500},
  69. { name: '管理', max: 16000},
  70. { name: '信息技术', max: 30000},
  71. { name: '客服', max: 38000},
  72. { name: '研发', max: 52000}
  73. ]
  74. * data: [
  75. {
  76. value: [4300, 10000, 28000, 35000, 50000],
  77. name: '完好率'
  78. }
  79. ]
  80. * name: 提示框name
  81. * */
  82. export function getRadar(id, horn, data, name) {
  83. if(name === undefined){
  84. name = "雷达数据";
  85. }
  86. if(data === undefined){
  87. message.error("没有找到报表数据,请检查!");
  88. return;
  89. }
  90. var myChart = EC.init(document.getElementById(id));
  91. let option = {
  92. tooltip: {},
  93. radar: {
  94. // shape: 'circle',
  95. radius: "60%",
  96. indicator: horn,
  97. axisLine: {
  98. lineStyle: {
  99. color: "#FFF"
  100. }
  101. },
  102. splitLine: {
  103. lineStyle: {
  104. color: "#2aafb7"
  105. }
  106. }
  107. },
  108. series: [{
  109. name: name,
  110. type: 'radar',
  111. // areaStyle: {normal: {}},
  112. data: data
  113. }]
  114. };
  115. myChart.setOption(option, true);
  116. }
  117. /*
  118. * 获取 雷达图 - 常用2 - 百分比
  119. * id: 元素ID
  120. * horn: [
  121. { name: '销售', max: 100},
  122. { name: '管理', max: 100},
  123. { name: '信息技术', max: 100},
  124. { name: '客服', max: 100},
  125. { name: '研发', max: 100}
  126. ]
  127. * data: [
  128. {
  129. value: [98, 98, 98, 98, 98],
  130. name: '完好率'
  131. }
  132. ]
  133. * name: 提示框name
  134. * */
  135. export function getRadar2(id, horn, data, name) {
  136. if(name === undefined){
  137. name = "雷达数据";
  138. }
  139. if(data === undefined){
  140. message.error("没有找到报表数据,请检查!");
  141. return;
  142. }
  143. var myChart = EC.init(document.getElementById(id));
  144. let option = {
  145. tooltip: {
  146. // formatter: '{b0}<br />{a}: {c0}'
  147. formatter: function (params, ticket, callback) {
  148. let value = params.data.name;
  149. horn.forEach((item, i)=>{
  150. value += '<br />'+item.name+':'+params.data.value[i]+"%"
  151. });
  152. return value;
  153. }
  154. },
  155. radar: {
  156. // shape: 'circle',
  157. radius: "60%",
  158. indicator: horn,
  159. axisLine: {
  160. lineStyle: {
  161. color: "#FFF"
  162. }
  163. },
  164. splitLine: {
  165. lineStyle: {
  166. color: "#2aafb7"
  167. }
  168. }
  169. },
  170. series: [{
  171. name: name,
  172. type: 'radar',
  173. // areaStyle: {normal: {}},
  174. data: data
  175. }]
  176. };
  177. myChart.setOption(option, true);
  178. }
  179. /*
  180. * 获取 柱状图 - 横向1
  181. * id: 元素ID
  182. * x: ['TOP6', 'TOP5', 'TOP4', 'TOP3', 'TOP2', 'TOP1']
  183. * data: [{
  184. value: 1000,
  185. itemStyle: {
  186. color: "#AAFAE0",
  187. barBorderRadius: [0, 3, 3, 0] // 柱子圆角
  188. }
  189. },{
  190. value: 2000,
  191. itemStyle: {
  192. color: "#FCCDBA",
  193. barBorderRadius: [0, 3, 3, 0] // 柱子圆角
  194. }
  195. },{
  196. value: 3000,
  197. itemStyle: {
  198. color: "#015EEA",
  199. barBorderRadius: [0, 3, 3, 0] // 柱子圆角
  200. }
  201. }]
  202. * name: 提示框name
  203. * */
  204. export function getBarHorizontal(id, x, data, name, tipX) {
  205. if(name === undefined){
  206. name = "数量";
  207. }
  208. if(data === undefined){
  209. message.error("没有找到报表数据,请检查!");
  210. return;
  211. }
  212. var myChart = EC.init(document.getElementById(id));
  213. let option = {
  214. tooltip: {
  215. // formatter: '{b0}<br />{a}: {c0}'
  216. formatter: function (params, ticket, callback) {
  217. if(tipX === undefined){
  218. return params.name+'<br />'+params.seriesName+': '+params.data.value;
  219. }else{
  220. return tipX[tipX.length - 1 - params.dataIndex]+'<br />'+params.seriesName+': '+params.data.value;
  221. }
  222. }
  223. },
  224. grid: {
  225. top: 10,
  226. left: 60,
  227. right: 40,
  228. bottom: 30,
  229. },
  230. xAxis: {
  231. type: 'value',
  232. boundaryGap: [0, 0.01],
  233. minInterval: 1, // 刻度不出现小数
  234. axisLine: {
  235. lineStyle: {
  236. color: "#011A3F"
  237. }
  238. },
  239. splitLine: {
  240. show: false
  241. },
  242. axisTick: {
  243. show: false
  244. },
  245. axisLabel: {
  246. fontSize: 12,
  247. color: "#FFF"
  248. },
  249. },
  250. yAxis: {
  251. type: 'category',
  252. data: x,
  253. axisLine: {
  254. lineStyle: {
  255. color: "#011A3F"
  256. }
  257. },
  258. axisTick: {
  259. show: false
  260. },
  261. axisLabel: {
  262. fontSize: 12,
  263. color: "#FFF"
  264. },
  265. splitLine: {
  266. show: false
  267. }
  268. },
  269. series: [
  270. {
  271. name: name,
  272. type: 'bar',
  273. barWidth: 6,
  274. data: data
  275. }
  276. ]
  277. };
  278. myChart.setOption(option, true);
  279. }
  280. /*
  281. * 获取 柱状图 - 纵向1
  282. * id: 元素ID
  283. * x: ['TOP3', 'TOP2', 'TOP1']
  284. * data: [{
  285. value: 1000,
  286. itemStyle: {
  287. color: "#AAFAE0",
  288. barBorderRadius: [3, 3, 0, 0] // 柱子圆角
  289. }
  290. },{
  291. value: 2000,
  292. itemStyle: {
  293. color: "#FCCDBA",
  294. barBorderRadius: [3, 3, 0, 0] // 柱子圆角
  295. }
  296. },{
  297. value: 3000,
  298. itemStyle: {
  299. color: "#015EEA",
  300. barBorderRadius: [3, 3, 0, 0] // 柱子圆角
  301. }
  302. }]
  303. * name: 提示框name
  304. * */
  305. export function getBarVertical(id, x, data, name) {
  306. if(name === undefined){
  307. name = "数量";
  308. }
  309. if(data === undefined){
  310. message.error("没有找到报表数据,请检查!");
  311. return;
  312. }
  313. var myChart = EC.init(document.getElementById(id));
  314. let option = {
  315. tooltip: {
  316. trigger: 'axis',
  317. axisPointer: {
  318. type: 'shadow'
  319. }
  320. },
  321. grid: {
  322. top: 15,
  323. left: 60,
  324. right: 40,
  325. bottom: 30,
  326. },
  327. yAxis: {
  328. type: 'value',
  329. boundaryGap: [0, 0.01],
  330. minInterval: 1, // 刻度不出现小数
  331. axisLine: {
  332. lineStyle: {
  333. color: "#011A3F"
  334. }
  335. },
  336. splitLine: {
  337. show: false
  338. },
  339. axisTick: {
  340. show: false
  341. },
  342. axisLabel: {
  343. fontSize: 12,
  344. color: "#FFF",
  345. // 改变纵坐标的单位,过大的时候处理成万
  346. formatter: function (value, index) {
  347. if(value >= 10000){
  348. return (value/10000).toFixed(0)+"万";
  349. }else{
  350. return value;
  351. }
  352. }
  353. },
  354. },
  355. xAxis: {
  356. type: 'category',
  357. data: x,
  358. axisLine: {
  359. lineStyle: {
  360. color: "#011A3F"
  361. }
  362. },
  363. axisTick: {
  364. show: false
  365. },
  366. axisLabel: {
  367. fontSize: 12,
  368. color: "#FFF"
  369. },
  370. splitLine: {
  371. show: false
  372. }
  373. },
  374. series: [
  375. {
  376. name: name,
  377. type: 'bar',
  378. barWidth: 6,
  379. data: data
  380. }
  381. ]
  382. };
  383. myChart.setOption(option, true);
  384. }
  385. /*
  386. * 获取 柱状图 - 纵向2 - 一轴多线
  387. * id: 元素ID
  388. * x: ['分中心1', '分中心2', '分中心3', '分中心4']
  389. *
  390. * data: [
  391. {
  392. name: '土建',
  393. type: 'bar',
  394. barWidth: 6,
  395. itemStyle: {
  396. color: "#4AB2EC",
  397. barBorderRadius: [3, 3, 0, 0] // 柱子圆角
  398. },
  399. data: [7.0, 23.2, 25.6, 76.7]
  400. },
  401. {
  402. name: '机电',
  403. type: 'bar',
  404. barWidth: 6,
  405. itemStyle: {
  406. color: "#F8CA9D",
  407. barBorderRadius: [3, 3, 0, 0] // 柱子圆角
  408. },
  409. data: [2.6, 5.9, 9.0, 26.4]
  410. },
  411. {
  412. name: '其他',
  413. type: 'bar',
  414. barWidth: 6,
  415. itemStyle: {
  416. color: "#8E6398",
  417. barBorderRadius: [3, 3, 0, 0] // 柱子圆角
  418. },
  419. data: [28.7, 70.7, 175.6, 182.2]
  420. },
  421. ]
  422. * */
  423. export function getBarVertical2(id, x, data) {
  424. if(data === undefined){
  425. message.error("没有找到报表数据,请检查!");
  426. return;
  427. }
  428. var myChart = EC.init(document.getElementById(id));
  429. let option = {
  430. tooltip: {
  431. trigger: 'axis',
  432. axisPointer: {
  433. type: 'shadow'
  434. }
  435. },
  436. grid: {
  437. top: 15,
  438. left: 60,
  439. right: 40,
  440. bottom: 30,
  441. },
  442. yAxis: {
  443. type: 'value',
  444. boundaryGap: [0, 0.01],
  445. axisLine: {
  446. lineStyle: {
  447. color: "#011A3F"
  448. }
  449. },
  450. splitLine: {
  451. show: false
  452. },
  453. axisTick: {
  454. show: false
  455. },
  456. axisLabel: {
  457. fontSize: 12,
  458. color: "#FFF",
  459. // 改变纵坐标的单位,过大的时候处理成万
  460. formatter: function (value, index) {
  461. if(value >= 10000){
  462. return (value/10000).toFixed(0)+"万";
  463. }else{
  464. return value;
  465. }
  466. }
  467. },
  468. },
  469. xAxis: {
  470. type: 'category',
  471. data: x,
  472. axisLine: {
  473. lineStyle: {
  474. color: "#011A3F"
  475. }
  476. },
  477. axisTick: {
  478. show: false
  479. },
  480. axisLabel: {
  481. fontSize: 12,
  482. color: "#FFF"
  483. },
  484. splitLine: {
  485. show: false
  486. }
  487. },
  488. series: data
  489. };
  490. myChart.setOption(option, true);
  491. }
  492. /*
  493. * 获取 柱状图 - 纵向2_1 - 一轴多线百分比
  494. * id: 元素ID
  495. * x: ['分中心1', '分中心2', '分中心3', '分中心4']
  496. *
  497. * data: [
  498. {
  499. name: '土建',
  500. type: 'bar',
  501. barWidth: 6,
  502. itemStyle: {
  503. color: "#4AB2EC",
  504. barBorderRadius: [3, 3, 0, 0] // 柱子圆角
  505. },
  506. data: [7.0, 23.2, 25.6, 76.7]
  507. },
  508. {
  509. name: '机电',
  510. type: 'bar',
  511. barWidth: 6,
  512. itemStyle: {
  513. color: "#F8CA9D",
  514. barBorderRadius: [3, 3, 0, 0] // 柱子圆角
  515. },
  516. data: [2.6, 5.9, 9.0, 26.4]
  517. },
  518. {
  519. name: '其他',
  520. type: 'bar',
  521. barWidth: 6,
  522. itemStyle: {
  523. color: "#8E6398",
  524. barBorderRadius: [3, 3, 0, 0] // 柱子圆角
  525. },
  526. data: [28.7, 70.7, 175.6, 182.2]
  527. },
  528. ]
  529. * */
  530. export function getBarVertical2_1(id, x, data) {
  531. if(data === undefined){
  532. message.error("没有找到报表数据,请检查!");
  533. return;
  534. }
  535. var myChart = EC.init(document.getElementById(id));
  536. let option = {
  537. tooltip: {
  538. trigger: 'axis',
  539. axisPointer: {
  540. type: 'shadow'
  541. },
  542. },
  543. grid: {
  544. top: 15,
  545. left: 60,
  546. right: 40,
  547. bottom: 30,
  548. },
  549. yAxis: {
  550. max: 100,
  551. type: 'value',
  552. boundaryGap: [0, 0.01],
  553. minInterval: 1, // 刻度不出现小数
  554. axisLine: {
  555. lineStyle: {
  556. color: "#011A3F"
  557. }
  558. },
  559. splitLine: {
  560. show: false
  561. },
  562. axisTick: {
  563. show: false
  564. },
  565. axisLabel: {
  566. fontSize: 12,
  567. color: "#FFF",
  568. formatter: '{value} %'
  569. },
  570. },
  571. xAxis: {
  572. type: 'category',
  573. data: x,
  574. axisLine: {
  575. lineStyle: {
  576. color: "#011A3F"
  577. }
  578. },
  579. axisTick: {
  580. show: false
  581. },
  582. axisLabel: {
  583. fontSize: 12,
  584. color: "#FFF"
  585. },
  586. splitLine: {
  587. show: false
  588. }
  589. },
  590. series: data
  591. };
  592. myChart.setOption(option, true);
  593. }
  594. /*
  595. * 获取 柱状图 - 纵向3
  596. * id: 元素ID
  597. * x: ['TOP6', 'TOP5', 'TOP4', 'TOP3', 'TOP2', 'TOP1']
  598. * data: [{
  599. value: 1000,
  600. itemStyle: {
  601. color: "#D8A0FE",
  602. barBorderRadius: [3, 3, 0, 0] // 柱子圆角
  603. }
  604. },{
  605. value: 2000,
  606. itemStyle: {
  607. color: "#D8A0FE",
  608. barBorderRadius: [3, 3, 0, 0] // 柱子圆角
  609. }
  610. },{
  611. value: 3000,
  612. itemStyle: {
  613. color: "#D8A0FE",
  614. barBorderRadius: [3, 3, 0, 0] // 柱子圆角
  615. }
  616. },{
  617. value: 4000,
  618. itemStyle: {
  619. color: "#D8A0FE",
  620. barBorderRadius: [3, 3, 0, 0] // 柱子圆角
  621. }
  622. },{
  623. value: 5000,
  624. itemStyle: {
  625. color: "#D8A0FE",
  626. barBorderRadius: [3, 3, 0, 0] // 柱子圆角
  627. }
  628. },{
  629. value: 5999,
  630. itemStyle: {
  631. color: "#D8A0FE",
  632. barBorderRadius: [3, 3, 0, 0] // 柱子圆角
  633. }
  634. },]
  635. * */
  636. export function getBarVertical3(id, x, data, name) {
  637. if(name === undefined){
  638. name = "数量";
  639. }
  640. if(data === undefined){
  641. message.error("没有找到报表数据,请检查!");
  642. return;
  643. }
  644. var myChart = EC.init(document.getElementById(id));
  645. let option = {
  646. tooltip: {
  647. trigger: 'axis',
  648. axisPointer: {
  649. type: 'shadow'
  650. }
  651. },
  652. grid: {
  653. top: 25,
  654. left: 80,
  655. right: 40,
  656. bottom: 30,
  657. },
  658. yAxis: {
  659. type: 'value',
  660. boundaryGap: [0, 0.01],
  661. minInterval: 1, // 刻度不出现小数
  662. axisLine: {
  663. lineStyle: {
  664. color: "#011A3F"
  665. }
  666. },
  667. splitLine: {
  668. show: false
  669. },
  670. axisTick: {
  671. show: false
  672. },
  673. axisLabel: {
  674. fontSize: 12,
  675. color: "#FFF",
  676. // 改变纵坐标的单位,过大的时候处理成万
  677. formatter: function (value, index) {
  678. if(value >= 10000){
  679. return (value/10000).toFixed(0)+"万";
  680. }else{
  681. return value;
  682. }
  683. }
  684. },
  685. },
  686. xAxis: {
  687. type: 'category',
  688. data: x,
  689. axisLine: {
  690. lineStyle: {
  691. color: "#011A3F"
  692. }
  693. },
  694. axisTick: {
  695. show: false
  696. },
  697. axisLabel: {
  698. fontSize: 12,
  699. color: "#FFF"
  700. },
  701. splitLine: {
  702. show: false
  703. }
  704. },
  705. series: [
  706. {
  707. name: name,
  708. type: 'bar',
  709. barWidth: 6,
  710. data: data
  711. }
  712. ]
  713. };
  714. myChart.setOption(option, true);
  715. }
  716. /*
  717. * 获取 饼图 - 常用1
  718. * id: 元素ID
  719. * data: 饼图数据
  720. * name: 提示框name
  721. * [
  722. {value: 335, name: '直接访问'},
  723. {value: 310, name: '邮件营销'},
  724. {value: 234, name: '联盟广告'},
  725. {value: 135, name: '视频广告'},
  726. {value: 1548, name: '搜索引擎'}
  727. ]
  728. * */
  729. export function getPie(id, data, name) {
  730. if(name === undefined){
  731. name = "占比";
  732. }
  733. if(data === undefined){
  734. message.error("没有找到报表数据,请检查!");
  735. return;
  736. }
  737. var myChart = EC.init(document.getElementById(id));
  738. let option = {
  739. tooltip: {
  740. trigger: 'item',
  741. formatter: "{a} <br/>{b} : {c} ({d}%)"
  742. },
  743. grid: {
  744. left: 44,
  745. right: 25,
  746. top: 56,
  747. bottom: 40
  748. },
  749. color: color,
  750. series: [{
  751. name: name,
  752. type: 'pie',
  753. radius: ['45%', '65%'],
  754. center: ['50%', '50%'],
  755. data: data,
  756. labelLine: {
  757. length: 10,
  758. length2: 10,
  759. lineStyle: {
  760. color: "#FFF"
  761. }
  762. },
  763. itemStyle: {
  764. emphasis: {
  765. shadowBlur: 10,
  766. shadowOffsetX: 0,
  767. shadowColor: 'rgba(0, 0, 0, 0.5)'
  768. },
  769. normal: {
  770. label: {
  771. textStyle: {
  772. color:'#FFF',
  773. fontSize: 14,
  774. }
  775. },
  776. },
  777. },
  778. label: {
  779. formatter: ['{b}','{d}%'].join('\n')
  780. }
  781. }]
  782. };
  783. myChart.setOption(option, true);
  784. }
  785. export default {
  786. getWordCloud,
  787. getRadar,
  788. getRadar2,
  789. getBarHorizontal,
  790. getBarVertical,
  791. getBarVertical2,
  792. getBarVertical2_1,
  793. getBarVertical3,
  794. getPie,
  795. color,
  796. }