config-ucharts.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * uCharts®
  3. * 高性能跨平台图表库,支持H5、APP、小程序(微信/支付宝/百度/头条/QQ/360)、Vue、Taro等支持canvas的框架平台
  4. * Copyright (c) 2021 QIUN®秋云 https://www.ucharts.cn All rights reserved.
  5. * Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  6. * 复制使用请保留本段注释,感谢支持开源!
  7. *
  8. * uCharts®官方网站
  9. * https://www.uCharts.cn
  10. *
  11. * 开源地址:
  12. * https://gitee.com/uCharts/uCharts
  13. *
  14. * uni-app插件市场地址:
  15. * http://ext.dcloud.net.cn/plugin?id=271
  16. *
  17. */
  18. // 主题颜色配置:如每个图表类型需要不同主题,请在对应图表类型上更改color属性
  19. const color = ['#1890FF', '#91CB74', '#FAC858', '#EE6666', '#73C0DE', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'];
  20. //事件转换函数,主要用作格式化x轴为时间轴,根据需求自行修改
  21. const formatDateTime = (timeStamp, returnType)=>{
  22. var date = new Date();
  23. date.setTime(timeStamp * 1000);
  24. var y = date.getFullYear();
  25. var m = date.getMonth() + 1;
  26. m = m < 10 ? ('0' + m) : m;
  27. var d = date.getDate();
  28. d = d < 10 ? ('0' + d) : d;
  29. var h = date.getHours();
  30. h = h < 10 ? ('0' + h) : h;
  31. var minute = date.getMinutes();
  32. var second = date.getSeconds();
  33. minute = minute < 10 ? ('0' + minute) : minute;
  34. second = second < 10 ? ('0' + second) : second;
  35. if(returnType == 'full'){return y + '-' + m + '-' + d + ' '+ h +':' + minute + ':' + second;}
  36. if(returnType == 'y-m-d'){return y + '-' + m + '-' + d;}
  37. if(returnType == 'h:m'){return h +':' + minute;}
  38. if(returnType == 'h:m:s'){return h +':' + minute +':' + second;}
  39. return [y, m, d, h, minute, second];
  40. }
  41. const cfu = {
  42. //demotype为自定义图表类型,一般不需要自定义图表类型,只需要改根节点上对应的类型即可
  43. "type":["pie","ring","rose","word","funnel","map","arcbar","line","column","mount","bar","area","radar","gauge","candle","mix","tline","tarea","scatter","bubble","demotype"],
  44. "range":["饼状图","圆环图","玫瑰图","词云图","漏斗图","地图","圆弧进度条","折线图","柱状图","山峰图","条状图","区域图","雷达图","仪表盘","K线图","混合图","时间轴折线","时间轴区域","散点图","气泡图","自定义类型"],
  45. //增加自定义图表类型,如果需要categories,请在这里加入您的图表类型,例如最后的"demotype"
  46. //自定义类型时需要注意"tline","tarea","scatter","bubble"等时间轴(矢量x轴)类图表,没有categories,不需要加入categories
  47. "categories":["line","column","mount","bar","area","radar","gauge","candle","mix","demotype"],
  48. //instance为实例变量承载属性,不要删除
  49. "instance":{},
  50. //option为opts及eopts承载属性,不要删除
  51. "option":{},
  52. //下面是自定义format配置,因除H5端外的其他端无法通过props传递函数,只能通过此属性对应下标的方式来替换
  53. "formatter":{
  54. "yAxisDemo1":function(val, index, opts){return val+'元'},
  55. "yAxisDemo2":function(val, index, opts){return val.toFixed(2)},
  56. "xAxisDemo1":function(val, index, opts){return val+'年';},
  57. "xAxisDemo2":function(val, index, opts){return formatDateTime(val,'h:m')},
  58. "xAxisDemo3":function(val, index, opts) {
  59. let len = opts.categories.length;
  60. let last = '';
  61. switch (true) {
  62. case len <= 10:
  63. console.log('1')
  64. last = val;
  65. break;
  66. case len > 10 && len <=25:
  67. if (index % 2 === 0) {
  68. last = val
  69. } else {
  70. last = ''
  71. }
  72. break;
  73. case len > 25:
  74. if (index % 4 === 0) {
  75. last = val
  76. } else {
  77. last = ''
  78. }
  79. break;
  80. }
  81. return last
  82. },
  83. "seriesDemo1":function(val, index, series, opts){return val+'元'},
  84. "tooltipDemo1":function(item, category, index, opts){
  85. if(index==0){
  86. return '随便用'+item.data+'年'
  87. }else{
  88. return '其他我没改'+item.data+'天'
  89. }
  90. },
  91. "pieDemo":function(val, index, series, opts){
  92. if(index !== undefined){
  93. return series[index].name+':'+series[index].data+'元'
  94. }
  95. },
  96. },
  97. //这里演示了自定义您的图表类型的option,可以随意命名,之后在组件上 type="demotype" 后,组件会调用这个花括号里的option,如果组件上还存在opts参数,会将demotype与opts中option合并后渲染图表。
  98. "demotype":{
  99. //我这里把曲线图当做了自定义图表类型,您可以根据需要随意指定类型或配置
  100. "type": "line",
  101. "color": color,
  102. "padding": [15,10,0,15],
  103. "xAxis": {
  104. "disableGrid": true,
  105. },
  106. "yAxis": {
  107. "gridType": "dash",
  108. "dashLength": 2,
  109. },
  110. "legend": {
  111. },
  112. "extra": {
  113. "line": {
  114. "type": "curve",
  115. "width": 2
  116. },
  117. }
  118. },
  119. //下面是自定义配置,请添加项目所需的通用配置
  120. "pie":{
  121. "type": "pie",
  122. "color": color,
  123. "padding": [5,5,5,5],
  124. "extra": {
  125. "pie": {
  126. "activeOpacity": 0.5,
  127. "activeRadius": 10,
  128. "offsetAngle": 0,
  129. "labelWidth": 15,
  130. "border": true,
  131. "borderWidth": 3,
  132. "borderColor": "#FFFFFF"
  133. },
  134. }
  135. },
  136. "ring":{
  137. "type": "ring",
  138. "color": color,
  139. "padding": [5,5,5,5],
  140. "rotate": false,
  141. "dataLabel": true,
  142. "legend": {
  143. "show": true,
  144. "position": "right",
  145. "lineHeight": 25,
  146. },
  147. "title": {
  148. "name": "收益率",
  149. "fontSize": 15,
  150. "color": "#666666"
  151. },
  152. "subtitle": {
  153. "name": "70%",
  154. "fontSize": 25,
  155. "color": "#7cb5ec"
  156. },
  157. "extra": {
  158. "ring": {
  159. "ringWidth":30,
  160. "activeOpacity": 0.5,
  161. "activeRadius": 10,
  162. "offsetAngle": 0,
  163. "labelWidth": 15,
  164. "border": true,
  165. "borderWidth": 3,
  166. "borderColor": "#FFFFFF"
  167. },
  168. },
  169. },
  170. "rose":{
  171. "type": "rose",
  172. "color": color,
  173. "padding": [5,5,5,5],
  174. "legend": {
  175. "show": true,
  176. "position": "left",
  177. "lineHeight": 25,
  178. },
  179. "extra": {
  180. "rose": {
  181. "type": "area",
  182. "minRadius": 50,
  183. "activeOpacity": 0.5,
  184. "activeRadius": 10,
  185. "offsetAngle": 0,
  186. "labelWidth": 15,
  187. "border": false,
  188. "borderWidth": 2,
  189. "borderColor": "#FFFFFF"
  190. },
  191. }
  192. },
  193. "word":{
  194. "type": "word",
  195. "color": color,
  196. "extra": {
  197. "word": {
  198. "type": "normal",
  199. "autoColors": false
  200. }
  201. }
  202. },
  203. "funnel":{
  204. "type": "funnel",
  205. "color": color,
  206. "padding": [15,15,0,15],
  207. "extra": {
  208. "funnel": {
  209. "activeOpacity": 0.3,
  210. "activeWidth": 10,
  211. "border": true,
  212. "borderWidth": 2,
  213. "borderColor": "#FFFFFF",
  214. "fillOpacity": 1,
  215. "labelAlign": "right"
  216. },
  217. }
  218. },
  219. "map":{
  220. "type": "map",
  221. "color": color,
  222. "padding": [0,0,0,0],
  223. "dataLabel": true,
  224. "extra": {
  225. "map": {
  226. "border": true,
  227. "borderWidth": 1,
  228. "borderColor": "#666666",
  229. "fillOpacity": 0.6,
  230. "activeBorderColor": "#F04864",
  231. "activeFillColor": "#FACC14",
  232. "activeFillOpacity": 1
  233. },
  234. }
  235. },
  236. "arcbar":{
  237. "type": "arcbar",
  238. "color": color,
  239. "title": {
  240. "name": "百分比",
  241. "fontSize": 25,
  242. "color": "#00FF00"
  243. },
  244. "subtitle": {
  245. "name": "默认标题",
  246. "fontSize": 15,
  247. "color": "#666666"
  248. },
  249. "extra": {
  250. "arcbar": {
  251. "type": "default",
  252. "width": 12,
  253. "backgroundColor": "#E9E9E9",
  254. "startAngle": 0.75,
  255. "endAngle": 0.25,
  256. "gap": 2
  257. }
  258. }
  259. },
  260. "line":{
  261. "type": "line",
  262. "color": color,
  263. "padding": [15,10,0,15],
  264. "xAxis": {
  265. "disableGrid": true,
  266. },
  267. "yAxis": {
  268. "gridType": "dash",
  269. "dashLength": 2,
  270. },
  271. "legend": {
  272. },
  273. "extra": {
  274. "line": {
  275. "type": "straight",
  276. "width": 2,
  277. "activeType": "hollow"
  278. },
  279. }
  280. },
  281. "tline":{
  282. "type": "line",
  283. "color": color,
  284. "padding": [15,10,0,15],
  285. "xAxis": {
  286. "disableGrid": false,
  287. "boundaryGap":"justify",
  288. },
  289. "yAxis": {
  290. "gridType": "dash",
  291. "dashLength": 2,
  292. "data":[
  293. {
  294. "min":0,
  295. "max":80
  296. }
  297. ]
  298. },
  299. "legend": {
  300. },
  301. "extra": {
  302. "line": {
  303. "type": "curve",
  304. "width": 2,
  305. "activeType": "hollow"
  306. },
  307. }
  308. },
  309. "tarea":{
  310. "type": "area",
  311. "color": color,
  312. "padding": [15,10,0,15],
  313. "xAxis": {
  314. "disableGrid": true,
  315. "boundaryGap":"justify",
  316. },
  317. "yAxis": {
  318. "gridType": "dash",
  319. "dashLength": 2,
  320. "data":[
  321. {
  322. "min":0,
  323. "max":80
  324. }
  325. ]
  326. },
  327. "legend": {
  328. },
  329. "extra": {
  330. "area": {
  331. "type": "curve",
  332. "opacity": 0.2,
  333. "addLine": true,
  334. "width": 2,
  335. "gradient": true,
  336. "activeType": "hollow"
  337. },
  338. }
  339. },
  340. "column":{
  341. "type": "column",
  342. "color": color,
  343. "padding": [15,15,0,5],
  344. "xAxis": {
  345. "disableGrid": true,
  346. },
  347. "yAxis": {
  348. "data":[{"min":0}]
  349. },
  350. "legend": {
  351. },
  352. "extra": {
  353. "column": {
  354. "type": "group",
  355. "width": 30,
  356. "activeBgColor": "#000000",
  357. "activeBgOpacity": 0.08
  358. },
  359. }
  360. },
  361. "mount":{
  362. "type": "mount",
  363. "color": color,
  364. "padding": [15,15,0,5],
  365. "xAxis": {
  366. "disableGrid": true,
  367. },
  368. "yAxis": {
  369. "data":[{"min":0}]
  370. },
  371. "legend": {
  372. },
  373. "extra": {
  374. "mount": {
  375. "type": "mount",
  376. "widthRatio": 1.5,
  377. },
  378. }
  379. },
  380. "bar":{
  381. "type": "bar",
  382. "color": color,
  383. "padding": [15,30,0,5],
  384. "xAxis": {
  385. "boundaryGap":"justify",
  386. "disableGrid":false,
  387. "min":0,
  388. "axisLine":false
  389. },
  390. "yAxis": {
  391. },
  392. "legend": {
  393. },
  394. "extra": {
  395. "bar": {
  396. "type": "group",
  397. "width": 30,
  398. "meterBorde": 1,
  399. "meterFillColor": "#FFFFFF",
  400. "activeBgColor": "#000000",
  401. "activeBgOpacity": 0.08
  402. },
  403. }
  404. },
  405. "area":{
  406. "type": "area",
  407. "color": color,
  408. "padding": [15,15,0,15],
  409. "xAxis": {
  410. "disableGrid": true,
  411. },
  412. "yAxis": {
  413. "gridType": "dash",
  414. "dashLength": 2,
  415. },
  416. "legend": {
  417. },
  418. "extra": {
  419. "area": {
  420. "type": "straight",
  421. "opacity": 0.2,
  422. "addLine": true,
  423. "width": 2,
  424. "gradient": false,
  425. "activeType": "hollow"
  426. },
  427. }
  428. },
  429. "radar":{
  430. "type": "radar",
  431. "color": color,
  432. "padding": [5,5,5,5],
  433. "dataLabel": false,
  434. "legend": {
  435. "show": true,
  436. "position": "right",
  437. "lineHeight": 25,
  438. },
  439. "extra": {
  440. "radar": {
  441. "gridType": "radar",
  442. "gridColor": "#CCCCCC",
  443. "gridCount": 3,
  444. "opacity": 0.2,
  445. "max": 200,
  446. "labelShow": true
  447. },
  448. }
  449. },
  450. "gauge":{
  451. "type": "gauge",
  452. "color": color,
  453. "title": {
  454. "name": "66Km/H",
  455. "fontSize": 25,
  456. "color": "#2fc25b",
  457. "offsetY": 50
  458. },
  459. "subtitle": {
  460. "name": "实时速度",
  461. "fontSize": 15,
  462. "color": "#1890ff",
  463. "offsetY": -50
  464. },
  465. "extra": {
  466. "gauge": {
  467. "type": "default",
  468. "width": 30,
  469. "labelColor": "#666666",
  470. "startAngle": 0.75,
  471. "endAngle": 0.25,
  472. "startNumber": 0,
  473. "endNumber": 100,
  474. "labelFormat": "",
  475. "splitLine": {
  476. "fixRadius": 0,
  477. "splitNumber": 10,
  478. "width": 30,
  479. "color": "#FFFFFF",
  480. "childNumber": 5,
  481. "childWidth": 12
  482. },
  483. "pointer": {
  484. "width": 24,
  485. "color": "auto"
  486. }
  487. }
  488. }
  489. },
  490. "candle":{
  491. "type": "candle",
  492. "color": color,
  493. "padding": [15,15,0,15],
  494. "enableScroll": true,
  495. "enableMarkLine": true,
  496. "dataLabel": false,
  497. "xAxis": {
  498. "labelCount": 4,
  499. "itemCount": 40,
  500. "disableGrid": true,
  501. "gridColor": "#CCCCCC",
  502. "gridType": "solid",
  503. "dashLength": 4,
  504. "scrollShow": true,
  505. "scrollAlign": "left",
  506. "scrollColor": "#A6A6A6",
  507. "scrollBackgroundColor": "#EFEBEF"
  508. },
  509. "yAxis": {
  510. },
  511. "legend": {
  512. },
  513. "extra": {
  514. "candle": {
  515. "color": {
  516. "upLine": "#f04864",
  517. "upFill": "#f04864",
  518. "downLine": "#2fc25b",
  519. "downFill": "#2fc25b"
  520. },
  521. "average": {
  522. "show": true,
  523. "name": ["MA5","MA10","MA30"],
  524. "day": [5,10,20],
  525. "color": ["#1890ff","#2fc25b","#facc14"]
  526. }
  527. },
  528. "markLine": {
  529. "type": "dash",
  530. "dashLength": 5,
  531. "data": [
  532. {
  533. "value": 2150,
  534. "lineColor": "#f04864",
  535. "showLabel": true
  536. },
  537. {
  538. "value": 2350,
  539. "lineColor": "#f04864",
  540. "showLabel": true
  541. }
  542. ]
  543. }
  544. }
  545. },
  546. "mix":{
  547. "type": "mix",
  548. "color": color,
  549. "padding": [15,15,0,15],
  550. "xAxis": {
  551. "disableGrid": true,
  552. },
  553. "yAxis": {
  554. "disabled": false,
  555. "disableGrid": false,
  556. "splitNumber": 5,
  557. "gridType": "dash",
  558. "dashLength": 4,
  559. "gridColor": "#CCCCCC",
  560. "padding": 10,
  561. "showTitle": true,
  562. "data": []
  563. },
  564. "legend": {
  565. },
  566. "extra": {
  567. "mix": {
  568. "column": {
  569. "width": 20
  570. }
  571. },
  572. }
  573. },
  574. "scatter":{
  575. "type": "scatter",
  576. "color":color,
  577. "padding":[15,15,0,15],
  578. "dataLabel":false,
  579. "xAxis": {
  580. "disableGrid": false,
  581. "gridType":"dash",
  582. "splitNumber":5,
  583. "boundaryGap":"justify",
  584. "min":0
  585. },
  586. "yAxis": {
  587. "disableGrid": false,
  588. "gridType":"dash",
  589. },
  590. "legend": {
  591. },
  592. "extra": {
  593. "scatter": {
  594. },
  595. }
  596. },
  597. "bubble":{
  598. "type": "bubble",
  599. "color":color,
  600. "padding":[15,15,0,15],
  601. "xAxis": {
  602. "disableGrid": false,
  603. "gridType":"dash",
  604. "splitNumber":5,
  605. "boundaryGap":"justify",
  606. "min":0,
  607. "max":250
  608. },
  609. "yAxis": {
  610. "disableGrid": false,
  611. "gridType":"dash",
  612. "data":[{
  613. "min":0,
  614. "max":150
  615. }]
  616. },
  617. "legend": {
  618. },
  619. "extra": {
  620. "bubble": {
  621. "border":2,
  622. "opacity": 0.5,
  623. },
  624. }
  625. }
  626. }
  627. export default cfu;