indexOptionChart.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. //从左往右颜色渐变
  2. export const GradualChange = (color1, color2) => {
  3. return new echarts.graphic.LinearGradient(1, 0, 0, 0, [
  4. { offset: 1, color: color1 + '' },
  5. { offset: 0, color: color2 + '' || color1 + '' }
  6. ]);
  7. };
  8. export const getColor = ([color1, color2]) => {
  9. // 右 下 左 上
  10. return new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  11. { offset: 0, color: color1 + '' },
  12. { offset: 1, color: color2 + '' || color1 + '' },
  13. ])
  14. }
  15. export const dateType = (date) => {
  16. let val = '';
  17. if (date) {
  18. val = `${date.slice(0, 4)}年${date.slice(4)}月`
  19. } else {
  20. val = date
  21. }
  22. return val
  23. }
  24. //折现波浪线颜色渐变
  25. export const getItemStyle = (c1, c2) => {
  26. return {
  27. color: {
  28. type: "linear",
  29. x: 0,
  30. y: 0,
  31. x2: 0,
  32. y2: 1,
  33. colorStops: [
  34. {
  35. offset: 0,
  36. color: c1 // 0% 处的颜色
  37. },
  38. {
  39. offset: 1,
  40. color: c2 // 100% 处的颜色
  41. }
  42. ],
  43. global: false // 缺省为 false
  44. }
  45. };
  46. }
  47. export const defaultMonth = ['01', "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
  48. const defaultColor = [GradualChange('#22D8FF', '#00B2FF'),
  49. GradualChange('#F0646C', '#F4994E'),
  50. GradualChange('#5EEDCC ', '#24C3F1'),
  51. GradualChange('#7178FF', '#D2A4FF'),
  52. GradualChange('#884DD2', '#DF63CC')]
  53. export const ringType = (
  54. color = [],
  55. data = [],
  56. title = {},
  57. legendFcuntion = {}
  58. ) => {
  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) => { return legendFcuntionValue(v) },
  85. textStyle: {
  86. rich: {
  87. a: {
  88. fontSize: 12,
  89. color: '#858892',
  90. padding: [0, 5, 0, 0]
  91. },
  92. b: {
  93. fontSize: 14,
  94. color: '#fff',
  95. padding: [0, 0, 0, 5]
  96. }
  97. }
  98. }
  99. },
  100. title,
  101. color: !!color.length ? color : defaultColor,
  102. series: [
  103. {
  104. type: 'pie',
  105. radius: ['55%', '70%'],
  106. avoidLabelOverlap: false,
  107. center: ['25%', '50%'],
  108. label: {
  109. show: false,
  110. position: 'center'
  111. },
  112. labelLine: {
  113. show: false
  114. },
  115. data: data
  116. }
  117. ]
  118. }
  119. }
  120. // 折现波浪
  121. export const discountedWave = (
  122. name = "",
  123. xAxis = [],
  124. series = [],
  125. legendShow = false,
  126. color = [],
  127. ) => {
  128. let option = {
  129. tooltip: {
  130. trigger: "axis",
  131. textStyle: {
  132. fontSize: 12,
  133. color: "#FFFFFF"
  134. },
  135. // formatter(param) {
  136. // let el = `<div class="dmp-echart-tooltip"><h4>${dateType(param[0].axisValue)}</h4>`;
  137. // param.forEach(item => {
  138. // el += `<p>
  139. // <span class="marker" style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-image: linear-gradient(to left,
  140. // ${item.color.colorStops[0].color}, ${item.color.colorStops[1].color});"></span>
  141. // <span>${item.seriesName}:${item.value}</span>
  142. // </p>`;
  143. // });
  144. // el += `</div>`;
  145. // return el;
  146. // }
  147. },
  148. grid: {
  149. top: 50,
  150. left: 5,
  151. bottom: 0,
  152. right: 5,
  153. containLabel: true
  154. },
  155. legend: {
  156. show: legendShow,
  157. icon: "circle",
  158. x: "right", // 可设定图例在左、右、居中
  159. itemWidth: 8, // 图例图形宽度
  160. itemHeight: 8,
  161. itemGap: 20,
  162. },
  163. xAxis: {
  164. type: "category",
  165. axisLine: {
  166. show: false // 不显示坐标轴
  167. },
  168. axisTick: {
  169. show: false // 不显示坐标轴刻度
  170. },
  171. axisLabel: {
  172. formatter: function (params, index) {
  173. return params.slice(5)
  174. },
  175. color: "#9B9DA5",
  176. margin: 16
  177. },
  178. data: xAxis,
  179. axisPointer: {
  180. type: "shadow",
  181. shadowStyle: {
  182. color: {
  183. type: "linear",
  184. x: 0,
  185. y: 0,
  186. x2: 0,
  187. y2: 1,
  188. colorStops: [
  189. {
  190. offset: 0,
  191. color: "rgba(31,207,245,0)" // 0% 处的颜色
  192. },
  193. {
  194. offset: 0.8,
  195. color: "rgba(31,207,245,0.15)" // 100% 处的颜色
  196. },
  197. {
  198. offset: 0.2,
  199. color: "rgba(31,207,245,0.15)" // 100% 处的颜色
  200. },
  201. {
  202. offset: 1,
  203. color: "rgba(31,207,245,0.05)"
  204. }
  205. ],
  206. global: false // 缺省为 false
  207. }
  208. }
  209. }
  210. },
  211. yAxis: {
  212. type: "value",
  213. splitNumber: 4,
  214. axisLine: {
  215. show: false
  216. },
  217. name: name,
  218. axisTick: {
  219. show: false
  220. },
  221. axisLabel: {
  222. color: "#9B9DA5",
  223. margin: 15,
  224. textStyle: {
  225. align: "right",
  226. baseline: "middle"
  227. }
  228. },
  229. nameLocation: "end",
  230. nameTextStyle: { color: "#9B9DA5", padding: [0, 0, 0, -40] },
  231. splitLine: {
  232. lineStyle: {
  233. type: "dotted",
  234. width: 0.2
  235. }
  236. }
  237. },
  238. series: [
  239. {
  240. // name: "设备告警",
  241. type: "line",
  242. smooth: true,
  243. symbol: "circle", // 实心
  244. symbolSize: 1, // 设定实心点的大小
  245. itemStyle: getItemStyle("#5EEDCC", "#24C3F1"),
  246. data: series,
  247. areaStyle: {
  248. normal: {
  249. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  250. {
  251. offset: 0,
  252. color: "rgba(36,121,253,0.1)"
  253. },
  254. {
  255. offset: 1,
  256. color: "rgba(19,194,247,0.3)"
  257. }
  258. ])
  259. }
  260. },
  261. lineStyle: {
  262. width: 1
  263. }
  264. },
  265. ]
  266. };
  267. return option;
  268. };
  269. //柱状
  270. export const columnOptionsChart = (
  271. name = "",
  272. xAxis = [],
  273. series = [],
  274. color = [],
  275. barWidth = 6
  276. ) => {
  277. let defaultData = [{
  278. name: '', type: 'bar', data: []
  279. }]
  280. let defaultColor = [['#0EAEFF', '#85E9FF'], ['#F0646C', '#F4994E']]
  281. let seriesConfiguration = () => {
  282. let seriesData = [];
  283. series.map((item, index) => {
  284. seriesData.push({
  285. name: item.name,
  286. type: 'bar',
  287. data: item.data,
  288. barWidth: barWidth,
  289. itemStyle: {
  290. normal: {
  291. barBorderRadius: [15, 15, 0, 0],
  292. color: getColor(color[index] || defaultColor[index]),
  293. }
  294. },
  295. barGap: '100%'
  296. })
  297. })
  298. return seriesData
  299. }
  300. let option = {
  301. tooltip: {
  302. trigger: "axis",
  303. axisPointer: {
  304. type: "shadow",
  305. shadowStyle: {
  306. color: {
  307. type: "linear",
  308. x: 0,
  309. y: 0,
  310. x2: 0,
  311. y2: 1,
  312. colorStops: [
  313. {
  314. offset: 0,
  315. color: "rgba(31,207,245,0)" // 0% 处的颜色
  316. },
  317. {
  318. offset: 0.8,
  319. color: "rgba(31,207,245,0.15)" // 100% 处的颜色
  320. },
  321. {
  322. offset: 0.2,
  323. color: "rgba(31,207,245,0.15)" // 100% 处的颜色
  324. },
  325. {
  326. offset: 1,
  327. color: "rgba(31,207,245,0.05)"
  328. }
  329. ],
  330. global: false // 缺省为 false
  331. }
  332. },
  333. crossStyle: {
  334. shadowBlur: 30,
  335. shadowColor: "rgba(0, 0, 0, 0.5)"
  336. }
  337. },
  338. extraCssText:
  339. "background:rgba(33,40,56,0.6);border-radius:4px;padding:6px 10px",
  340. textStyle: {
  341. fontSize: 12,
  342. color: "#FFFFFF"
  343. },
  344. formatter(param) {
  345. let el = `<div class="dmp-echart-tooltip" style="text-align: center;"><h4>${dateType(param[0].axisValue)}</h4>`;
  346. param.forEach(item => {
  347. el += `<p style="text-align: left;">
  348. <span style="display:inline-block;margin-right:5px;border-radius:4px;width:12px;height:8px;background-image: linear-gradient(to left,
  349. ${item.color.colorStops[0].color}, ${item.color.colorStops[1].color})"></span>
  350. <span>${item.seriesName}:${item.value.toFixed(2)}</span>
  351. </p>`;
  352. });
  353. el += `</div>`;
  354. return el;
  355. }
  356. },
  357. grid: {
  358. top: 50,
  359. left: 0,
  360. bottom: 0,
  361. right: 0,
  362. containLabel: true
  363. },
  364. xAxis: {
  365. type: "category",
  366. axisLine: {
  367. show: false // 不显示坐标轴
  368. },
  369. axisTick: {
  370. show: false // 不显示坐标轴刻度
  371. },
  372. axisLabel: {
  373. formatter: function (params, index) {
  374. if (params.length == 2) {
  375. return params + '月';
  376. } else {
  377. return params.slice(5) + '月';
  378. }
  379. },
  380. color: "#9B9DA5",
  381. margin: 15
  382. },
  383. data: !!xAxis.length ? xAxis : defaultMonth
  384. },
  385. yAxis: {
  386. type: "value",
  387. splitNumber: 4,
  388. name: name,
  389. axisLine: {
  390. show: false
  391. },
  392. axisTick: {
  393. show: false
  394. },
  395. axisLabel: {
  396. color: "#9B9DA5",
  397. margin: 15,
  398. textStyle: {
  399. align: "right",
  400. baseline: "middle"
  401. }
  402. },
  403. nameLocation: "end",
  404. nameTextStyle: { color: "#9B9DA5", padding: [0, 0, 0, -40] },
  405. splitLine: {
  406. lineStyle: {
  407. type: "dotted",
  408. width: 0.5
  409. }
  410. }
  411. },
  412. legend: {
  413. show: false,
  414. x: 'right',
  415. icon: "circle",
  416. itemWidth: 8, // 图例图形宽度
  417. itemHeight: 8,
  418. itemGap: 20
  419. },
  420. series: seriesConfiguration() || defaultData
  421. };
  422. return option;
  423. }