indexOptionChart.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. import echarts from 'echarts';
  2. //从左往右颜色渐变
  3. export const GradualChange = (color1, color2) => {
  4. return new echarts.graphic.LinearGradient(1, 0, 0, 0, [
  5. { offset: 1, color: color1 + '' },
  6. { offset: 0, color: color2 + '' || color1 + '' }
  7. ]);
  8. };
  9. export const getColor = ([color1, color2]) => {
  10. // 右 下 左 上
  11. return new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  12. { offset: 0, color: color1 + '' },
  13. { offset: 1, color: color2 + '' || color1 + '' }
  14. ]);
  15. };
  16. export const dateType = (date) => {
  17. let val = '';
  18. if (date) {
  19. val = `${date.slice(0, 4)}年${date.slice(4)}月`;
  20. } else {
  21. val = date;
  22. }
  23. return val;
  24. };
  25. //折现波浪线颜色渐变
  26. export const getItemStyle = (c1, c2) => {
  27. return {
  28. color: {
  29. type: 'linear',
  30. x: 0,
  31. y: 0,
  32. x2: 0,
  33. y2: 1,
  34. colorStops: [
  35. {
  36. offset: 0,
  37. color: c1 // 0% 处的颜色
  38. },
  39. {
  40. offset: 1,
  41. color: c2 // 100% 处的颜色
  42. }
  43. ],
  44. global: false // 缺省为 false
  45. }
  46. };
  47. };
  48. export const defaultMonth = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
  49. export const defaultName = ['name1', 'name2', 'name3'];
  50. const defaultColor = [
  51. GradualChange('#22D8FF', '#00B2FF'),
  52. GradualChange('#F0646C', '#F4994E'),
  53. GradualChange('#5EEDCC ', '#24C3F1'),
  54. GradualChange('#7178FF', '#D2A4FF'),
  55. GradualChange('#884DD2', '#DF63CC')
  56. ];
  57. // 饼图
  58. export const ringType = (color = [], data = [], title = {}, legendFcuntion = {}) => {
  59. let legendFcuntionValue = (v) => {
  60. let val = '';
  61. data.map((item) => {
  62. if (item.name == v) {
  63. if (legendFcuntion.type == '%') {
  64. val = `{a|${v}} · · · · · · {b|${parseInt((item.value / legendFcuntion.total).toFixed(2) * 100) || 0}%}`;
  65. } else {
  66. val = `{a|${v}} · · · · · · {b|${item.value}}`;
  67. }
  68. }
  69. });
  70. return val;
  71. };
  72. return {
  73. tooltip: {
  74. trigger: 'item'
  75. },
  76. legend: {
  77. orient: 'vertical',
  78. right: 10,
  79. top: 80,
  80. itemGap: 10,
  81. itemWidth: 12, // 图例图形宽度
  82. itemHeight: 8,
  83. type: 'scroll',
  84. formatter: (v) => {
  85. return legendFcuntionValue(v);
  86. },
  87. textStyle: {
  88. rich: {
  89. a: {
  90. fontSize: 12,
  91. color: '#858892',
  92. padding: [0, 5, 0, 0]
  93. },
  94. b: {
  95. fontSize: 14,
  96. color: '#fff',
  97. padding: [0, 0, 0, 5]
  98. }
  99. }
  100. }
  101. },
  102. title,
  103. color: !!color.length ? color : defaultColor,
  104. series: [
  105. {
  106. type: 'pie',
  107. // radius: ['55%', '70%'],
  108. radius: ['55%', '70%'],
  109. center: ['25%', '50%'],
  110. avoidLabelOverlap: false,
  111. // center: ['25%', '50%'],
  112. label: {
  113. show: false,
  114. position: 'center'
  115. },
  116. labelLine: {
  117. show: false
  118. },
  119. data: data
  120. }
  121. ]
  122. };
  123. };
  124. // 折现波浪
  125. export const discountedWave = (name = '', xAxis = [], series = [], legendShow = false, color = []) => {
  126. let option = {
  127. tooltip: {
  128. trigger: 'axis',
  129. textStyle: {
  130. fontSize: 12,
  131. color: '#FFFFFF'
  132. }
  133. // formatter(param) {
  134. // let el = `<div class="dmp-echart-tooltip"><h4>${dateType(param[0].axisValue)}</h4>`;
  135. // param.forEach(item => {
  136. // el += `<p>
  137. // <span class="marker" style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-image: linear-gradient(to left,
  138. // ${item.color.colorStops[0].color}, ${item.color.colorStops[1].color});"></span>
  139. // <span>${item.seriesName}:${item.value}</span>
  140. // </p>`;
  141. // });
  142. // el += `</div>`;
  143. // return el;
  144. // }
  145. },
  146. grid: {
  147. top: 50,
  148. left: 5,
  149. bottom: 0,
  150. right: 5,
  151. containLabel: true
  152. },
  153. legend: {
  154. show: legendShow,
  155. icon: 'circle',
  156. x: 'right', // 可设定图例在左、右、居中
  157. itemWidth: 8, // 图例图形宽度
  158. itemHeight: 8,
  159. itemGap: 20
  160. },
  161. xAxis: {
  162. type: 'category',
  163. axisLine: {
  164. show: false // 不显示坐标轴
  165. },
  166. axisTick: {
  167. show: false // 不显示坐标轴刻度
  168. },
  169. axisLabel: {
  170. formatter: function (params, index) {
  171. return params.slice(5);
  172. },
  173. color: '#9B9DA5',
  174. margin: 16
  175. },
  176. data: xAxis,
  177. axisPointer: {
  178. type: 'shadow',
  179. shadowStyle: {
  180. color: {
  181. type: 'linear',
  182. x: 0,
  183. y: 0,
  184. x2: 0,
  185. y2: 1,
  186. colorStops: [
  187. {
  188. offset: 0,
  189. color: 'rgba(31,207,245,0)' // 0% 处的颜色
  190. },
  191. {
  192. offset: 0.8,
  193. color: 'rgba(31,207,245,0.15)' // 100% 处的颜色
  194. },
  195. {
  196. offset: 0.2,
  197. color: 'rgba(31,207,245,0.15)' // 100% 处的颜色
  198. },
  199. {
  200. offset: 1,
  201. color: 'rgba(31,207,245,0.05)'
  202. }
  203. ],
  204. global: false // 缺省为 false
  205. }
  206. }
  207. }
  208. },
  209. yAxis: {
  210. type: 'value',
  211. splitNumber: 4,
  212. axisLine: {
  213. show: false
  214. },
  215. name: name,
  216. axisTick: {
  217. show: false
  218. },
  219. axisLabel: {
  220. color: '#9B9DA5',
  221. margin: 15,
  222. textStyle: {
  223. align: 'right',
  224. baseline: 'middle'
  225. }
  226. },
  227. nameLocation: 'end',
  228. nameTextStyle: { color: '#9B9DA5', padding: [0, 0, 0, -40] },
  229. splitLine: {
  230. lineStyle: {
  231. type: 'dotted',
  232. width: 0.2
  233. }
  234. }
  235. },
  236. series: [
  237. {
  238. // name: "设备告警",
  239. type: 'line',
  240. smooth: true,
  241. symbol: 'circle', // 实心
  242. symbolSize: 1, // 设定实心点的大小
  243. itemStyle: getItemStyle('#5EEDCC', '#24C3F1'),
  244. data: series,
  245. areaStyle: {
  246. normal: {
  247. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  248. {
  249. offset: 0,
  250. color: 'rgba(36,121,253,0.1)'
  251. },
  252. {
  253. offset: 1,
  254. color: 'rgba(19,194,247,0.3)'
  255. }
  256. ])
  257. }
  258. },
  259. lineStyle: {
  260. width: 1
  261. }
  262. }
  263. ]
  264. };
  265. return option;
  266. };
  267. //柱状日期
  268. export const columnOptionsChart = (name = '', xAxis = [], series = [], color = [], barWidth = 6) => {
  269. let defaultData = [
  270. {
  271. name: '',
  272. type: 'bar',
  273. data: []
  274. }
  275. ];
  276. let defaultColor = [
  277. ['#0EAEFF', '#85E9FF'],
  278. ['#F0646C', '#F4994E']
  279. ];
  280. let seriesConfiguration = () => {
  281. let seriesData = [];
  282. series.map((item, index) => {
  283. seriesData.push({
  284. name: item.name,
  285. type: 'bar',
  286. data: item.data,
  287. barWidth: barWidth,
  288. itemStyle: {
  289. normal: {
  290. barBorderRadius: [15, 15, 0, 0],
  291. color: getColor(color[index] || defaultColor[index])
  292. }
  293. },
  294. barGap: '100%'
  295. });
  296. });
  297. return seriesData;
  298. };
  299. let option = {
  300. tooltip: {
  301. trigger: 'axis',
  302. axisPointer: {
  303. type: 'shadow',
  304. shadowStyle: {
  305. color: {
  306. type: 'linear',
  307. x: 0,
  308. y: 0,
  309. x2: 0,
  310. y2: 1,
  311. colorStops: [
  312. {
  313. offset: 0,
  314. color: 'rgba(31,207,245,0)' // 0% 处的颜色
  315. },
  316. {
  317. offset: 0.8,
  318. color: 'rgba(31,207,245,0.15)' // 100% 处的颜色
  319. },
  320. {
  321. offset: 0.2,
  322. color: 'rgba(31,207,245,0.15)' // 100% 处的颜色
  323. },
  324. {
  325. offset: 1,
  326. color: 'rgba(31,207,245,0.05)'
  327. }
  328. ],
  329. global: false // 缺省为 false
  330. }
  331. },
  332. crossStyle: {
  333. shadowBlur: 30,
  334. shadowColor: 'rgba(0, 0, 0, 0.5)'
  335. }
  336. },
  337. extraCssText: 'background:rgba(33,40,56,0.6);border-radius:4px;padding:6px 10px',
  338. textStyle: {
  339. fontSize: 12,
  340. color: '#FFFFFF'
  341. },
  342. formatter(param) {
  343. let el = `<div class="dmp-echart-tooltip" style="text-align: center;"><h4>${dateType(param[0].axisValue)}</h4>`;
  344. param.forEach((item) => {
  345. el += `<p style="text-align: left;">
  346. <span style="display:inline-block;margin-right:5px;border-radius:4px;width:12px;height:8px;background-image: linear-gradient(to left,
  347. ${item.color.colorStops[0].color}, ${item.color.colorStops[1].color})"></span>
  348. <span>${item.seriesName}:${item.value.toFixed(2)}</span>
  349. </p>`;
  350. });
  351. el += `</div>`;
  352. return el;
  353. }
  354. },
  355. grid: {
  356. top: 50,
  357. left: 0,
  358. bottom: 0,
  359. right: 0,
  360. containLabel: true
  361. },
  362. xAxis: {
  363. type: 'category',
  364. axisLine: {
  365. show: false // 不显示坐标轴
  366. },
  367. axisTick: {
  368. show: false // 不显示坐标轴刻度
  369. },
  370. axisLabel: {
  371. formatter: function (params, index) {
  372. if (params.length == 2) {
  373. return params + '月';
  374. } else {
  375. return params.slice(5) + '月';
  376. }
  377. },
  378. color: '#9B9DA5',
  379. margin: 15
  380. },
  381. data: !!xAxis.length ? xAxis : defaultMonth
  382. },
  383. yAxis: {
  384. type: 'value',
  385. splitNumber: 4,
  386. name: name,
  387. axisLine: {
  388. show: false
  389. },
  390. axisTick: {
  391. show: false
  392. },
  393. axisLabel: {
  394. color: '#9B9DA5',
  395. margin: 15,
  396. textStyle: {
  397. align: 'right',
  398. baseline: 'middle'
  399. }
  400. },
  401. nameLocation: 'end',
  402. nameTextStyle: { color: '#9B9DA5', padding: [0, 0, 0, -40] },
  403. splitLine: {
  404. lineStyle: {
  405. type: 'dotted',
  406. width: 0.5
  407. }
  408. }
  409. },
  410. legend: {
  411. show: false,
  412. x: 'right',
  413. icon: 'circle',
  414. itemWidth: 8, // 图例图形宽度
  415. itemHeight: 8,
  416. itemGap: 20
  417. },
  418. series: seriesConfiguration() || defaultData
  419. };
  420. return option;
  421. };
  422. //柱状name 单柱状
  423. export const columnOptionsChartName = (name = '', xAxis = [], series = [], color = [], barWidth = 6) => {
  424. let defaultData = [
  425. {
  426. name: '',
  427. type: 'bar',
  428. data: []
  429. }
  430. ];
  431. let defaultColor = [
  432. ['#0EAEFF', '#85E9FF'],
  433. ['#F0646C', '#F4994E']
  434. ];
  435. let seriesConfiguration = () => {
  436. let seriesData = [
  437. {
  438. type: 'bar',
  439. data: [],
  440. barWidth: barWidth,
  441. itemStyle: {
  442. normal: {
  443. barBorderRadius: [15, 15, 0, 0],
  444. color: getColor(color[0] || defaultColor[0])
  445. }
  446. },
  447. barGap: '100%'
  448. }
  449. ];
  450. series.map((item, index) => {
  451. seriesData[0].data.push(item.data);
  452. });
  453. return seriesData;
  454. };
  455. let option = {
  456. tooltip: {
  457. trigger: 'axis',
  458. axisPointer: {
  459. type: 'shadow',
  460. shadowStyle: {
  461. color: {
  462. type: 'linear',
  463. x: 0,
  464. y: 0,
  465. x2: 0,
  466. y2: 1,
  467. colorStops: [
  468. {
  469. offset: 0,
  470. color: 'rgba(31,207,245,0)' // 0% 处的颜色
  471. },
  472. {
  473. offset: 0.8,
  474. color: 'rgba(31,207,245,0.15)' // 100% 处的颜色
  475. },
  476. {
  477. offset: 0.2,
  478. color: 'rgba(31,207,245,0.15)' // 100% 处的颜色
  479. },
  480. {
  481. offset: 1,
  482. color: 'rgba(31,207,245,0.05)'
  483. }
  484. ],
  485. global: false // 缺省为 false
  486. }
  487. },
  488. crossStyle: {
  489. shadowBlur: 30,
  490. shadowColor: 'rgba(0, 0, 0, 0.5)'
  491. }
  492. },
  493. extraCssText: 'background:rgba(33,40,56,0.6);border-radius:4px;padding:6px 10px',
  494. textStyle: {
  495. fontSize: 12,
  496. color: '#FFFFFF'
  497. },
  498. formatter(param) {
  499. let el = ``;
  500. param.forEach((item) => {
  501. el += `<p style="text-align: left;">
  502. <span style="display:inline-block;margin-right:5px;border-radius:4px;width:12px;height:8px;background-image: linear-gradient(to left,
  503. ${item.color.colorStops[0].color}, ${item.color.colorStops[1].color})"></span>
  504. <span>${item.name}:${item.value}${name}</span>
  505. </p>`;
  506. });
  507. el += ``;
  508. return el;
  509. }
  510. },
  511. grid: {
  512. top: 50,
  513. left: 10,
  514. bottom: 0,
  515. right: 0,
  516. containLabel: true
  517. },
  518. xAxis: {
  519. type: 'category',
  520. axisLine: {
  521. show: false // 不显示坐标轴
  522. },
  523. axisTick: {
  524. show: false // 不显示坐标轴刻度
  525. },
  526. axisLabel: {
  527. formatter: function (params, index) {
  528. return params;
  529. },
  530. color: '#9B9DA5',
  531. margin: 15
  532. },
  533. data: !!xAxis.length ? xAxis : defaultName
  534. },
  535. yAxis: {
  536. type: 'value',
  537. splitNumber: 4,
  538. name: name,
  539. axisLine: {
  540. show: false
  541. },
  542. axisTick: {
  543. show: false
  544. },
  545. axisLabel: {
  546. color: '#9B9DA5',
  547. margin: 15,
  548. textStyle: {
  549. align: 'right',
  550. baseline: 'middle'
  551. }
  552. },
  553. nameLocation: 'end',
  554. nameTextStyle: { color: '#9B9DA5', padding: [0, 0, 0, -40] },
  555. splitLine: {
  556. lineStyle: {
  557. type: 'dotted',
  558. width: 0.5
  559. }
  560. }
  561. },
  562. legend: {
  563. show: false,
  564. x: 'right',
  565. icon: 'circle',
  566. itemWidth: 8, // 图例图形宽度
  567. itemHeight: 8,
  568. itemGap: 20
  569. },
  570. series: seriesConfiguration() || defaultData
  571. };
  572. return option;
  573. };
  574. // 柱状图堆叠
  575. export const columnOptionsChartStacking = (name = '', xAxis = [], series = [], color = [], barWidth = 6) => {
  576. let defaultData = [
  577. {
  578. name: '',
  579. type: 'bar',
  580. data: []
  581. }
  582. ];
  583. let defaultColor = [
  584. // ['#0EAEFF', '#85E9FF'],
  585. ['#0EAEFF', '#0EAEFF'],
  586. ['#85E9FF', '#85E9FF']
  587. // ['#F0646C', '#F4994E']
  588. ];
  589. let seriesConfiguration = () => {
  590. let seriesData = [
  591. {
  592. type: 'bar',
  593. data: [],
  594. name: '',
  595. barWidth: barWidth,
  596. itemStyle: {
  597. normal: {
  598. barBorderRadius: [15, 15, 0, 0],
  599. color: getColor(color[0] || defaultColor[0])
  600. }
  601. },
  602. barGap: '100%'
  603. },
  604. {
  605. type: 'bar',
  606. data: [],
  607. name: '',
  608. barWidth: barWidth,
  609. itemStyle: {
  610. normal: {
  611. barBorderRadius: [15, 15, 0, 0],
  612. color: getColor(color[1] || defaultColor[1])
  613. }
  614. },
  615. barGap: '-100%',
  616. z: '1'
  617. }
  618. ];
  619. series.map((item, index) => {
  620. seriesData[index].data = item.data;
  621. seriesData[index].name = item.name;
  622. });
  623. return seriesData;
  624. };
  625. let option = {
  626. tooltip: {
  627. trigger: 'axis',
  628. axisPointer: {
  629. type: 'shadow',
  630. shadowStyle: {
  631. color: {
  632. type: 'linear',
  633. x: 0,
  634. y: 0,
  635. x2: 0,
  636. y2: 1,
  637. colorStops: [
  638. {
  639. offset: 0,
  640. color: 'rgba(31,207,245,0)' // 0% 处的颜色
  641. },
  642. {
  643. offset: 0.8,
  644. color: 'rgba(31,207,245,0.15)' // 100% 处的颜色
  645. },
  646. {
  647. offset: 0.2,
  648. color: 'rgba(31,207,245,0.15)' // 100% 处的颜色
  649. },
  650. {
  651. offset: 1,
  652. color: 'rgba(31,207,245,0.05)'
  653. }
  654. ],
  655. global: false // 缺省为 false
  656. }
  657. },
  658. crossStyle: {
  659. shadowBlur: 30,
  660. shadowColor: 'rgba(0, 0, 0, 0.5)'
  661. }
  662. },
  663. extraCssText: 'background:rgba(33,40,56,0.6);border-radius:4px;padding:6px 10px',
  664. textStyle: {
  665. fontSize: 12,
  666. color: '#FFFFFF'
  667. },
  668. formatter(param) {
  669. let el = ``;
  670. param.forEach((item) => {
  671. el += `<p style="text-align: left;">
  672. <span style="display:inline-block;margin-right:5px;border-radius:4px;width:12px;height:8px;background-image: linear-gradient(to left,
  673. ${item.color.colorStops[0].color}, ${item.color.colorStops[1].color})"></span>
  674. <span>${item.seriesName}:${item.value}${name}</span>
  675. </p>`;
  676. });
  677. el += ``;
  678. return el;
  679. }
  680. },
  681. grid: {
  682. top: 50,
  683. left: 0,
  684. bottom: 0,
  685. right: 0,
  686. containLabel: true
  687. },
  688. xAxis: {
  689. type: 'category',
  690. axisLine: {
  691. show: false // 不显示坐标轴
  692. },
  693. axisTick: {
  694. show: false // 不显示坐标轴刻度
  695. },
  696. axisLabel: {
  697. formatter: function (params, index) {
  698. return params;
  699. },
  700. color: '#9B9DA5',
  701. margin: 15
  702. },
  703. data: !!xAxis.length ? xAxis : defaultName
  704. },
  705. yAxis: {
  706. type: 'value',
  707. splitNumber: 4,
  708. name: name,
  709. axisLine: {
  710. show: false
  711. },
  712. axisTick: {
  713. show: false
  714. },
  715. axisLabel: {
  716. color: '#9B9DA5',
  717. margin: 15,
  718. textStyle: {
  719. align: 'right',
  720. baseline: 'middle'
  721. }
  722. },
  723. nameLocation: 'end',
  724. nameTextStyle: { color: '#9B9DA5', padding: [0, 0, 0, -40] },
  725. splitLine: {
  726. lineStyle: {
  727. type: 'dotted',
  728. width: 0.5
  729. }
  730. }
  731. },
  732. legend: {
  733. show: false,
  734. x: 'right',
  735. icon: 'circle',
  736. itemWidth: 8, // 图例图形宽度
  737. itemHeight: 8,
  738. itemGap: 20
  739. },
  740. series: seriesConfiguration() || defaultData
  741. };
  742. return option;
  743. };
  744. // 折线日期 间隔4个
  745. export const discountedChart = (name = '', xAxis = [], series = [], legendShow = false, color = []) => {
  746. let option = {
  747. tooltip: {
  748. trigger: 'axis',
  749. textStyle: {
  750. fontSize: 12,
  751. color: '#FFFFFF'
  752. }
  753. // formatter(param) {
  754. // let el = `<div class="dmp-echart-tooltip"><h4>${dateType(param[0].axisValue)}</h4>`;
  755. // param.forEach(item => {
  756. // el += `<p>
  757. // <span class="marker" style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-image: linear-gradient(to left,
  758. // ${item.color.colorStops[0].color}, ${item.color.colorStops[1].color});"></span>
  759. // <span>${item.seriesName}:${item.value}</span>
  760. // </p>`;
  761. // });
  762. // el += `</div>`;
  763. // return el;
  764. // }
  765. },
  766. grid: {
  767. top: 50,
  768. left: 5,
  769. bottom: 0,
  770. right: 5,
  771. containLabel: true
  772. },
  773. legend: {
  774. show: legendShow,
  775. icon: 'circle',
  776. x: 'right', // 可设定图例在左、右、居中
  777. itemWidth: 8, // 图例图形宽度
  778. itemHeight: 8,
  779. itemGap: 20
  780. },
  781. xAxis: {
  782. type: 'category',
  783. axisLine: {
  784. show: false // 不显示坐标轴
  785. },
  786. axisTick: {
  787. show: false // 不显示坐标轴刻度
  788. },
  789. axisLabel: {
  790. interval: 4,
  791. // formatter: function (params, index) {
  792. // return params.slice(5);
  793. // },
  794. color: '#9B9DA5',
  795. margin: 16
  796. },
  797. data: xAxis,
  798. axisPointer: {
  799. type: 'shadow',
  800. shadowStyle: {
  801. color: {
  802. type: 'linear',
  803. x: 0,
  804. y: 0,
  805. x2: 0,
  806. y2: 1,
  807. colorStops: [
  808. {
  809. offset: 0,
  810. color: 'rgba(31,207,245,0)' // 0% 处的颜色
  811. },
  812. {
  813. offset: 0.8,
  814. color: 'rgba(31,207,245,0.15)' // 100% 处的颜色
  815. },
  816. {
  817. offset: 0.2,
  818. color: 'rgba(31,207,245,0.15)' // 100% 处的颜色
  819. },
  820. {
  821. offset: 1,
  822. color: 'rgba(31,207,245,0.05)'
  823. }
  824. ],
  825. global: false // 缺省为 false
  826. }
  827. }
  828. }
  829. },
  830. yAxis: {
  831. type: 'value',
  832. splitNumber: 4,
  833. axisLine: {
  834. show: false
  835. },
  836. name: name,
  837. axisTick: {
  838. show: false
  839. },
  840. axisLabel: {
  841. color: '#9B9DA5',
  842. margin: 15,
  843. textStyle: {
  844. align: 'right',
  845. baseline: 'middle'
  846. }
  847. },
  848. nameLocation: 'end',
  849. nameTextStyle: { color: '#9B9DA5', padding: [0, 0, 0, -40] },
  850. splitLine: {
  851. lineStyle: {
  852. type: 'dotted',
  853. width: 0.2
  854. }
  855. }
  856. },
  857. series: [
  858. {
  859. // name: "设备告警",
  860. type: 'line',
  861. smooth: true,
  862. symbol: 'circle', // 实心
  863. symbolSize: 1, // 设定实心点的大小
  864. itemStyle: getItemStyle('#5EEDCC', '#24C3F1'),
  865. data: series,
  866. areaStyle: {
  867. normal: {
  868. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  869. {
  870. offset: 0,
  871. color: 'rgba(36,121,253,0.1)'
  872. },
  873. {
  874. offset: 1,
  875. color: 'rgba(19,194,247,0.3)'
  876. }
  877. ])
  878. }
  879. },
  880. lineStyle: {
  881. width: 1
  882. }
  883. }
  884. ]
  885. };
  886. return option;
  887. };
  888. // 漏斗图
  889. export const funnelChart = (dataseries = [], series = []) => {
  890. // var colors=[['#22D8FF','#00B2FF']]
  891. var colorList = [
  892. {
  893. colorStops: [
  894. {
  895. offset: 0,
  896. color: '#22D8FF' // 0% 处的颜色
  897. },
  898. {
  899. offset: 1,
  900. color: '#00B2FF' // 100% 处的颜色
  901. }
  902. ]
  903. },
  904. {
  905. colorStops: [
  906. {
  907. offset: 0,
  908. color: '#5EEDCC' // 0% 处的颜色
  909. },
  910. {
  911. offset: 1,
  912. color: '#24C3F1' // 100% 处的颜色
  913. }
  914. ]
  915. },
  916. {
  917. colorStops: [
  918. {
  919. offset: 0,
  920. color: '#F0646C' // 0% 处的颜色
  921. },
  922. {
  923. offset: 1,
  924. color: '#F4994E' // 100% 处的颜色
  925. }
  926. ]
  927. },
  928. {
  929. colorStops: [
  930. {
  931. offset: 0,
  932. color: '#7178FF' // 0% 处的颜色
  933. },
  934. {
  935. offset: 1,
  936. color: '#D2A4FF ' // 100% 处的颜色
  937. }
  938. ]
  939. },
  940. {
  941. colorStops: [
  942. {
  943. offset: 0,
  944. color: '#884DD2' // 0% 处的颜色
  945. },
  946. {
  947. offset: 1,
  948. color: '#DF63CC' // 100% 处的颜色
  949. }
  950. ]
  951. }
  952. ];
  953. let option = {
  954. title: {
  955. text: ''
  956. },
  957. // backgroundColor:'#ffffff',
  958. color: colorList,
  959. series: [
  960. {
  961. top: 0,
  962. type: 'funnel',
  963. left: '10%',
  964. top: '15%',
  965. width: '50%',
  966. height: '85%',
  967. gap: 0,
  968. minSize: 50,
  969. maxSize: 260,
  970. label: {
  971. show: true,
  972. position: 'inside',
  973. // formatter: '{d}'
  974. formatter: function (data) {
  975. return data.percent.toFixed(0) + '%';
  976. },
  977. textStyle: {
  978. shadowOffsetX: 0,
  979. fontSize: '14',
  980. shadowColor: 'rgba(0, 0, 0, 0)',
  981. color: '#FFFFFF'
  982. }
  983. },
  984. data: dataseries
  985. },
  986. {
  987. top: 0,
  988. type: 'funnel',
  989. left: '0',
  990. width: '30%',
  991. height: '85%',
  992. top: '15%',
  993. gap: 16,
  994. z: 1,
  995. // minSize: 50,
  996. // maxSize: 50,
  997. label: {
  998. normal: {
  999. // padding :[11,25],
  1000. formatter: function (params) {
  1001. let el = `{a|${params.name}} {b|${params.value}}`;
  1002. return el;
  1003. },
  1004. textStyle: {
  1005. rich: {
  1006. a: {
  1007. fontSize: 12,
  1008. color: '#858892',
  1009. padding: [0, 5, 0, 0]
  1010. },
  1011. b: {
  1012. fontSize: 14,
  1013. color: '#fff',
  1014. padding: [0, 0, 0, 5]
  1015. }
  1016. }
  1017. }
  1018. }
  1019. },
  1020. //右侧的百分比显示的地方
  1021. labelLine: {
  1022. show: true,
  1023. normal: {
  1024. show: false,
  1025. length: 200,
  1026. position: 'center',
  1027. lineStyle: {
  1028. width: 1,
  1029. color: 'red',
  1030. type: 'solid'
  1031. }
  1032. }
  1033. },
  1034. // 主体是透明的
  1035. itemStyle: {
  1036. normal: {
  1037. color: 'transparent',
  1038. borderWidth: 0,
  1039. opacity: 1
  1040. }
  1041. },
  1042. data: series
  1043. }
  1044. ]
  1045. };
  1046. return option;
  1047. };
  1048. // 柱状图 双个柱图
  1049. export const columnOptionsChartss = (name = '', xAxis = [], series = [], dataseries = [], dataName = [], color = [], barWidth = 6) => {
  1050. let defaultData = [
  1051. {
  1052. name: '',
  1053. type: 'bar',
  1054. data: []
  1055. }
  1056. ];
  1057. let defaultColor = [
  1058. ['#0EAEFF', '#85E9FF'],
  1059. ['#F0646C', '#F4994E']
  1060. ];
  1061. let seriesConfiguration = () => {
  1062. let seriesData = [
  1063. {
  1064. name: '',
  1065. type: 'bar',
  1066. data: [],
  1067. barWidth: barWidth,
  1068. itemStyle: {
  1069. normal: {
  1070. barBorderRadius: [15, 15, 0, 0],
  1071. color: getColor(color[0] || defaultColor[0])
  1072. }
  1073. },
  1074. barGap: '100%'
  1075. },
  1076. {
  1077. name: '',
  1078. type: 'bar',
  1079. data: [],
  1080. barWidth: barWidth,
  1081. itemStyle: {
  1082. normal: {
  1083. barBorderRadius: [15, 15, 0, 0],
  1084. color: getColor(color[1] || defaultColor[1])
  1085. }
  1086. },
  1087. barGap: '100%'
  1088. }
  1089. ];
  1090. series.map((item, index) => {
  1091. seriesData[0].data.push(item.data);
  1092. seriesData[0].name = dataName[0];
  1093. });
  1094. dataseries.map((items, indexs) => {
  1095. seriesData[1].data.push(items.data);
  1096. seriesData[1].name = dataName[1];
  1097. });
  1098. return seriesData;
  1099. };
  1100. let option = {
  1101. tooltip: {
  1102. trigger: 'axis',
  1103. axisPointer: {
  1104. type: 'shadow',
  1105. shadowStyle: {
  1106. color: {
  1107. type: 'linear',
  1108. x: 0,
  1109. y: 0,
  1110. x2: 0,
  1111. y2: 1,
  1112. colorStops: [
  1113. {
  1114. offset: 0,
  1115. color: 'rgba(31,207,245,0)' // 0% 处的颜色
  1116. },
  1117. {
  1118. offset: 0.8,
  1119. color: 'rgba(31,207,245,0.15)' // 100% 处的颜色
  1120. },
  1121. {
  1122. offset: 0.2,
  1123. color: 'rgba(31,207,245,0.15)' // 100% 处的颜色
  1124. },
  1125. {
  1126. offset: 1,
  1127. color: 'rgba(31,207,245,0.05)'
  1128. }
  1129. ],
  1130. global: false // 缺省为 false
  1131. }
  1132. },
  1133. crossStyle: {
  1134. shadowBlur: 30,
  1135. shadowColor: 'rgba(0, 0, 0, 0.5)'
  1136. }
  1137. },
  1138. extraCssText: 'background:rgba(33,40,56,0.6);border-radius:4px;padding:6px 10px',
  1139. textStyle: {
  1140. fontSize: 12,
  1141. color: '#FFFFFF'
  1142. },
  1143. formatter(param) {
  1144. let el = ``;
  1145. let elitem = ``;
  1146. param.forEach((item) => {
  1147. elitem = `<p>${item.name}</p>`;
  1148. el += `<p style="text-align: left;">
  1149. <span style="display:inline-block;margin-right:5px;border-radius:4px;width:12px;height:8px;background-image: linear-gradient(to left,
  1150. ${item.color.colorStops[0].color}, ${item.color.colorStops[1].color})"></span>
  1151. <span>${item.seriesName}:${item.value}${name}</span>
  1152. </p>`;
  1153. });
  1154. el += ``;
  1155. return elitem + el;
  1156. }
  1157. },
  1158. grid: {
  1159. top: 50,
  1160. left: 10,
  1161. bottom: 0,
  1162. right: 0,
  1163. containLabel: true
  1164. },
  1165. xAxis: {
  1166. type: 'category',
  1167. axisLine: {
  1168. show: false // 不显示坐标轴
  1169. },
  1170. axisTick: {
  1171. show: false // 不显示坐标轴刻度
  1172. },
  1173. axisLabel: {
  1174. formatter: function (params, index) {
  1175. return params;
  1176. },
  1177. color: '#9B9DA5',
  1178. margin: 15
  1179. },
  1180. data: !!xAxis.length ? xAxis : defaultName
  1181. },
  1182. yAxis: {
  1183. type: 'value',
  1184. splitNumber: 4,
  1185. name: name,
  1186. axisLine: {
  1187. show: false
  1188. },
  1189. axisTick: {
  1190. show: false
  1191. },
  1192. axisLabel: {
  1193. color: '#9B9DA5',
  1194. margin: 15,
  1195. textStyle: {
  1196. align: 'right',
  1197. baseline: 'middle'
  1198. }
  1199. },
  1200. nameLocation: 'end',
  1201. nameTextStyle: { color: '#9B9DA5', padding: [0, 0, 0, -40] },
  1202. splitLine: {
  1203. lineStyle: {
  1204. type: 'dotted',
  1205. width: 0.5
  1206. }
  1207. }
  1208. },
  1209. legend: {
  1210. show: true,
  1211. x: 'right',
  1212. icon: 'circle',
  1213. itemWidth: 8, // 图例图形宽度
  1214. itemHeight: 8,
  1215. itemGap: 20,
  1216. textStyle: {
  1217. color: '#FFF'
  1218. }
  1219. },
  1220. series: seriesConfiguration() || defaultData
  1221. };
  1222. return option;
  1223. };