EachartOptions.js 10.0 KB

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