dataUiOptions.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. export function getTheme() {
  2. // ("zen" | "hack" | "concrete" | "")
  3. return localStorage.isDark ? 'hack' : ''
  4. }
  5. export function getLineData({ xAxis = [] as any[], datas = [] as number[][], legend = [] as string[], suffix = '', width = 1000, height = 400, responsive = false, zoom = false, modulo = 10, padding = 30, useArea = true }) {
  6. const colors = ['#6376DD', '#FBBB04']
  7. const maxVal = Math.max(...datas.flat())
  8. // 设置最大值为 接近这个数值并且比这个数值稍大的整数
  9. const radio = 10 ** (maxVal.toString().length - 2)
  10. const max = Math.ceil(maxVal * 1.4 / radio) * radio
  11. const config = {
  12. theme: getTheme(),
  13. responsive,
  14. "chart": {
  15. "fontFamily": "inherit",
  16. "paddingTop": 0,
  17. height,
  18. width,
  19. "zoom": {
  20. "show": zoom
  21. },
  22. "padding": {
  23. "top": 30,
  24. "right": padding,
  25. "bottom": 34,
  26. "left": padding
  27. },
  28. "grid": {
  29. "position": "start",
  30. "labels": {
  31. "show": true,
  32. "fontSize": 12,
  33. "axis": {
  34. "fontSize": 12
  35. },
  36. "yAxis": {
  37. "commonScaleSteps": 10,
  38. "scaleMin": 0,
  39. "scaleMax": max,
  40. },
  41. "xAxisLabels": {
  42. "show": true,
  43. "values": xAxis,
  44. "fontSize": 12,
  45. "showOnlyFirstAndLast": false,
  46. "showOnlyAtModulo": true,
  47. modulo,
  48. "yOffset": 8
  49. }
  50. }
  51. },
  52. "labels": {
  53. "fontSize": 12,
  54. "prefix": "",
  55. suffix
  56. },
  57. "legend": {
  58. "show": legend.length > 1,
  59. "fontSize": 12
  60. },
  61. "title": {
  62. "text": " ",
  63. "show": false
  64. },
  65. "userOptions": {
  66. "show": false
  67. },
  68. },
  69. "line": {
  70. "radius": 3,
  71. "useGradient": true,
  72. "strokeWidth": 2,
  73. "labels": {},
  74. "area": {
  75. "useGradient": true,
  76. "opacity": "26"
  77. }
  78. },
  79. }
  80. const dataset = datas.map((data, i) => {
  81. return {
  82. "name": legend[i],
  83. "series": data,
  84. "color": colors[i],
  85. "type": "line",
  86. "shape": "circle",
  87. "useArea": useArea,
  88. "useProgression": false,
  89. "dataLabels": true,
  90. "smooth": true,
  91. "dashed": false,
  92. "useTag": "none"
  93. }
  94. })
  95. return { config, dataset }
  96. }
  97. export function getBarData({ xAxis = [] as any[], datas = [] as number[][], legend = [] as string[], suffix = '', width = 1000, height = 400, responsive = false, zoom = false, modulo = 10, padding = 30, colors = ['#6376DD', '#FBBB04'] }) {
  98. const config = {
  99. theme: getTheme(),
  100. responsive,
  101. "chart": {
  102. "fontFamily": "inherit",
  103. "paddingTop": 0,
  104. height,
  105. width,
  106. "zoom": {
  107. "show": zoom
  108. },
  109. "padding": {
  110. "top": 20,
  111. "right": padding,
  112. "bottom": 20,
  113. "left": padding
  114. },
  115. "grid": {
  116. "position": "middle",
  117. "labels": {
  118. "show": true,
  119. "fontSize": 16,
  120. "axis": {
  121. "fontSize": 16
  122. },
  123. "yAxis": {
  124. "commonScaleSteps": 10,
  125. "scaleMin": 0,
  126. },
  127. "xAxisLabels": {
  128. "show": true,
  129. "values": xAxis,
  130. "fontSize": 16,
  131. "showOnlyFirstAndLast": false,
  132. "showOnlyAtModulo": true,
  133. modulo: xAxis.length < modulo ? xAxis.length : modulo,
  134. "yOffset": 2
  135. }
  136. }
  137. },
  138. "labels": {
  139. "fontSize": 16,
  140. "prefix": "",
  141. suffix
  142. },
  143. "legend": {
  144. "show": legend.length > 1,
  145. "fontSize": 16
  146. },
  147. "title": {
  148. "text": " ",
  149. "show": false
  150. },
  151. "userOptions": {
  152. "show": false
  153. },
  154. },
  155. "bar": {
  156. "borderRadius": 2,
  157. "useGradient": true,
  158. "periodGap": 0.5,
  159. "border": {
  160. "useSerieColor": false,
  161. "strokeWidth": 1,
  162. "stroke": "#FFFFFFff"
  163. },
  164. "labels": {
  165. "show": true,
  166. "offsetY": -5,
  167. "rounding": 0,
  168. "color": "#1A1A1Aff",
  169. "formatter": null
  170. },
  171. "serieName": {
  172. "show": false,
  173. "offsetY": -6,
  174. "useAbbreviation": true,
  175. "abbreviationSize": 3,
  176. "useSerieColor": true,
  177. "color": "#1A1A1Aff",
  178. "bold": false
  179. }
  180. },
  181. }
  182. const dataset = datas.map((data, i) => {
  183. return {
  184. "name": legend[i],
  185. "series": data,
  186. "color": colors[i],
  187. "type": "bar",
  188. scaleSteps: 10,
  189. scaleLabel: "Blue circles"
  190. }
  191. })
  192. return { config, dataset }
  193. }
  194. export function getLine2Data({ xAxis = [] as any[], datas = [] as number[][], legend = [] as string[], suffix = '', width = 500, height = 300, color = 'rgb(1, 191, 236)' }) {
  195. const max = 100
  196. const config = {
  197. theme: getTheme(),
  198. "responsive": false,
  199. "chart": {
  200. "fontFamily": "inherit",
  201. "paddingTop": 0,
  202. "backgroundColor": "transparent",
  203. "color": "#888888",
  204. height,
  205. width,
  206. "zoom": {
  207. "show": false
  208. },
  209. "padding": {
  210. "top": 10,
  211. "right": 24,
  212. "bottom": 30,
  213. "left": 24
  214. },
  215. "grid": {
  216. "position": "start",
  217. "labels": {
  218. "color": "#888888",
  219. "fontSize": 14,
  220. "axis": {
  221. "fontSize": 14
  222. },
  223. "yAxis": {
  224. "commonScaleSteps": 10,
  225. "scaleMin": 0,
  226. "scaleMax": max,
  227. },
  228. "xAxisLabels": {
  229. "show": true,
  230. "color": "#888888",
  231. "values": xAxis,
  232. "fontSize": 14,
  233. "modulo": 112,
  234. "showOnlyFirstAndLast": false,
  235. "yOffset": 8
  236. }
  237. }
  238. },
  239. "labels": {
  240. "fontSize": 14,
  241. "prefix": "",
  242. suffix
  243. },
  244. "legend": {
  245. "show": legend.length > 1,
  246. "color": "#888888",
  247. "fontSize": 14
  248. },
  249. "title": {
  250. "text": " ",
  251. "show": false
  252. },
  253. "userOptions": {
  254. "show": false
  255. }
  256. },
  257. "line": {
  258. "radius": 3,
  259. "useGradient": true,
  260. "strokeWidth": 2,
  261. "labels": {
  262. "rounding": 22,
  263. },
  264. "area": {
  265. "useGradient": true,
  266. "opacity": "26"
  267. }
  268. },
  269. }
  270. const dataset = datas.map((data, i) => {
  271. return {
  272. "name": legend[i],
  273. "series": data,
  274. "color": color,
  275. "type": "line",
  276. "shape": "circle",
  277. "useArea": true,
  278. "useProgression": false,
  279. "dataLabels": true,
  280. "smooth": true,
  281. "dashed": false,
  282. "useTag": "none"
  283. }
  284. })
  285. return { config, dataset }
  286. }
  287. export function getPieData({ datas = [] as number[][], legend = [] as string[], types = [] as number[], width = 500, height = 1300, responsive = false }) {
  288. const colorList = ['#4285F4', '#2ecc71', '#FBBB04', '#e67e22', '#FF0000'].reverse()
  289. const config = {
  290. theme: getTheme(),
  291. "responsive": responsive,
  292. "backgroundColor": "transparent",
  293. style: {
  294. "backgroundColor": "transparent",
  295. chart: {
  296. "fontFamily": "inherit",
  297. "paddingTop": 0,
  298. "backgroundColor": "transparent",
  299. height,
  300. width,
  301. "padding": {
  302. "top": 0,
  303. "right": 0,
  304. "bottom": 0,
  305. "left": 0
  306. },
  307. "title": {
  308. "text": " ",
  309. "show": false,
  310. },
  311. "legend": {
  312. "show": true,
  313. "bold": false,
  314. "backgroundColor": "transparent",
  315. "fontSize": 14,
  316. "roundingValue": 0,
  317. "roundingPercentage": 0
  318. },
  319. "layout": {
  320. "labels": {
  321. value: { rounding: 0, show: true, formatter: null },
  322. percentage: {
  323. bold: true,
  324. fontSize: 14,
  325. rounding: 0,
  326. formatter: null,
  327. },
  328. name: { bold: false, fontSize: 14 },
  329. "hollow": {
  330. "total": {
  331. "fontSize": 18,
  332. "text": "总计",
  333. "value": {
  334. "fontSize": 18,
  335. }
  336. },
  337. "average": {
  338. "show": false,
  339. },
  340. },
  341. },
  342. },
  343. },
  344. },
  345. "userOptions": {
  346. "show": false
  347. },
  348. }
  349. // const dataset = [{ "name": "Series 1", "values": [100] }, { "name": "Series 2", "values": [50] }, { "name": "Series 3", "values": [25] }, { "name": "Series 4", "values": [12.5] }]
  350. const dataset = datas.map((data, i) => {
  351. return { "name": legend[i], "values": data, color: colorList[types[i] - 1] }
  352. })
  353. return { config, dataset }
  354. }
  355. export function getPieSmallData({ datas = [] as number[][], legend = [] as string[], colors = ['#2ecc71', '#4285F4', '#FBBB04', '#FF0000', '#e67e22'].reverse() as string[], width = 500, height = 1300, responsive = false }) {
  356. const config = {
  357. theme: getTheme(),
  358. "responsive": responsive,
  359. "backgroundColor": "transparent",
  360. style: {
  361. "backgroundColor": "transparent",
  362. chart: {
  363. "fontFamily": "inherit",
  364. "paddingTop": 0,
  365. "gradientIntensity": "0",
  366. "backgroundColor": "transparent",
  367. height,
  368. width,
  369. "padding": {
  370. "top": 0,
  371. "right": 0,
  372. "bottom": 0,
  373. "left": 0
  374. },
  375. "title": {
  376. "text": "",
  377. "show": false,
  378. },
  379. "legend": {
  380. "show": true,
  381. "bold": false,
  382. "backgroundColor": "transparent",
  383. "fontSize": 14,
  384. "roundingValue": 0,
  385. "roundingPercentage": 0
  386. },
  387. "layout": {
  388. "donut": {
  389. "strokeWidth": "40",
  390. "borderWidth": "2",
  391. "useShadow": false,
  392. },
  393. "labels": {
  394. "dataLabels": {
  395. "show": true,
  396. "useLabelSlots": false,
  397. "hideUnderValue": 0,
  398. "prefix": "",
  399. "suffix": ""
  400. },
  401. value: { rounding: 0, show: true, formatter: null },
  402. percentage: {
  403. bold: true,
  404. fontSize: 14,
  405. rounding: 0,
  406. formatter: null,
  407. },
  408. name: { bold: false, fontSize: 14 },
  409. "hollow": {
  410. "total": {
  411. "fontSize": 18,
  412. "text": "总计",
  413. "value": {
  414. "fontSize": 18,
  415. }
  416. },
  417. "average": {
  418. "show": false,
  419. },
  420. },
  421. },
  422. },
  423. },
  424. },
  425. "userOptions": {
  426. "show": false
  427. },
  428. }
  429. // const dataset = [{ "name": "Series 1", "values": [100] }, { "name": "Series 2", "values": [50] }, { "name": "Series 3", "values": [25] }, { "name": "Series 4", "values": [12.5] }]
  430. const dataset = datas.map((data, i) => {
  431. return { "name": legend[i], "values": data, color: colors[i] }
  432. })
  433. return { config, dataset }
  434. }
  435. export function getGaugeData({ value = 50 }) {
  436. const config = {
  437. theme: getTheme(),
  438. "responsive": false,
  439. "customPalette": [],
  440. "style": {
  441. "fontFamily": "inherit",
  442. "chart": {
  443. "backgroundColor": "#FFFFFFff",
  444. "color": "#1A1A1Aff",
  445. "animation": {
  446. "use": true,
  447. "speed": 0.5,
  448. "acceleration": 0.5
  449. },
  450. "layout": {
  451. "track": {
  452. "size": 1,
  453. "useGradient": true,
  454. "gradientIntensity": 20
  455. },
  456. "markers": {
  457. "color": "#1A1A1Aff",
  458. "bold": true,
  459. "fontSizeRatio": 1,
  460. "offsetY": 0,
  461. "roundingValue": 0
  462. },
  463. "pointer": {
  464. "type": "pointy",
  465. "size": 1,
  466. "stroke": "#1A1A1Aff",
  467. "strokeWidth": 12,
  468. "useRatingColor": true,
  469. "color": "#CCCCCCff",
  470. "circle": {
  471. "radius": 10,
  472. "stroke": "#1A1A1Aff",
  473. "strokeWidth": 2,
  474. "color": "#FFFFFFff"
  475. }
  476. }
  477. },
  478. "legend": {
  479. "fontSize": 48,
  480. "prefix": "",
  481. "suffix": "%",
  482. "roundingValue": 2,
  483. "showPlusSymbol": false,
  484. "useRatingColor": true,
  485. "color": "#1A1A1Aff",
  486. "formatter": null
  487. },
  488. "title": {
  489. "text": " ",
  490. "show": true,
  491. }
  492. }
  493. },
  494. "userOptions": {
  495. "show": false,
  496. },
  497. "translations": {
  498. "base": "Base"
  499. }
  500. }
  501. const dataset = {
  502. "series": [{ "from": 0, "to": 25, "color": "#4DABF7", "id": "111" }, { "from": 25, "to": 50, "color": "#69DB7C", "id": "111" }, { "from": 50, "to": 75, "color": "#FFA94D", "id": "111" }, { "from": 75, "to": 100, "color": "#FF6B6B", "id": "222" }],
  503. value
  504. }
  505. return { config, dataset }
  506. }