基础折线图.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. /*
  2. * @description: 配置,参考https://g2plot.antv.antgroup.com/examples
  3. * @Date: 2023-03-27 14:38:23
  4. * @Author: xing.heng
  5. */
  6. // 配置版本号
  7. const version = '0.0.1'
  8. // 分类
  9. const category = 'Line'
  10. // 标题
  11. const title = '基础折线图'
  12. // 类别, new Line()
  13. const chartType = 'Line'
  14. // 用于标识,唯一,和文件夹名称一致
  15. const name = 'JiChuZheXianTu'
  16. // 右侧配置项
  17. const setting = [
  18. {
  19. label: '横坐标',
  20. // 设置组件类型, select / input / colorPicker
  21. type: 'select',
  22. // 字段
  23. field: 'xField',
  24. optionField: 'xField', // 对应options中的字段
  25. // 是否多选
  26. multiple: false,
  27. // 绑定的值
  28. value: '',
  29. // tab页。 data: 数据, custom: 自定义
  30. tabName: 'data'
  31. },
  32. {
  33. label: '指标',
  34. // 设置组件类型
  35. type: 'select',
  36. // 字段
  37. field: 'yField',
  38. // 对应options中的字段
  39. optionField: 'yField',
  40. // 是否多选
  41. multiple: false,
  42. value: '',
  43. tabName: 'data'
  44. },
  45. /** 样式配置 **/
  46. // 图表 graph
  47. {
  48. label: '折线点样式',
  49. type: 'select',
  50. field: 'point_shape',
  51. optionField: 'point.shape',
  52. // 是否多选
  53. multiple: false,
  54. value: '',
  55. tabName: 'custom',
  56. options: [
  57. {
  58. label: '无',
  59. value: false
  60. },
  61. {
  62. label: '空心圆',
  63. value: 'hollow-circle'
  64. },
  65. {
  66. label: '圆形',
  67. value: 'circle'
  68. },
  69. {
  70. label: '正方形',
  71. value: 'square'
  72. },
  73. {
  74. label: '菱形',
  75. value: 'diamond'
  76. },
  77. {
  78. label: '三角形',
  79. value: 'triangle'
  80. },
  81. {
  82. label: '六边形',
  83. value: 'hexagon'
  84. },
  85. {
  86. label: '菱形交叉',
  87. value: 'bowtie'
  88. },
  89. {
  90. label: '十字形',
  91. value: 'cross'
  92. },
  93. {
  94. label: 'I形',
  95. value: 'tick'
  96. },
  97. {
  98. label: '加号',
  99. value: 'plus'
  100. },
  101. {
  102. label: '连字号',
  103. value: 'hyphen'
  104. }
  105. ],
  106. groupName: 'graph'
  107. },
  108. {
  109. label: '折线点大小',
  110. type: 'inputNumber',
  111. field: 'point_size',
  112. optionField: 'point.size',
  113. value: 2,
  114. tabName: 'custom',
  115. groupName: 'graph'
  116. },
  117. {
  118. label: '折线点颜色',
  119. type: 'colorPicker',
  120. field: 'point_style_fill',
  121. optionField: 'point.style.fill',
  122. // 是否多选
  123. multiple: false,
  124. value: '#ffffff',
  125. tabName: 'custom',
  126. groupName: 'graph'
  127. },
  128. {
  129. label: '数据标签',
  130. type: 'switchNumber', // 设置组件类型
  131. field: 'label_style_opacity', // 字段
  132. optionField: 'label.style.opacity', // 对应options中的字段
  133. value: 0,
  134. tabName: 'custom',
  135. groupName: 'graph'
  136. },
  137. {
  138. label: '数据标签颜色',
  139. type: 'colorPicker',
  140. field: 'label_style_fill',
  141. optionField: 'label.style.fill',
  142. value: '#fff',
  143. tabName: 'custom',
  144. groupName: 'graph'
  145. },
  146. {
  147. label: '数据标签大小',
  148. type: 'inputNumber',
  149. field: 'label_style_fontSize',
  150. optionField: 'label.style.fontSize',
  151. value: 12,
  152. tabName: 'custom',
  153. groupName: 'graph'
  154. },
  155. {
  156. label: '折线宽度',
  157. type: 'inputNumber',
  158. field: 'lineStyle_lineWidth',
  159. optionField: 'lineStyle.lineWidth',
  160. value: 2,
  161. tabName: 'custom',
  162. groupName: 'graph'
  163. },
  164. {
  165. label: '折线颜色',
  166. type: 'gradual',
  167. field: 'lineStyle_stroke',
  168. optionField: 'lineStyle.stroke',
  169. value: 'l(0) 0:#5F92F9 1:#62FF00',
  170. tabName: 'custom',
  171. groupName: 'graph'
  172. },
  173. // 网格线 grid
  174. {
  175. label: '虚线',
  176. type: 'switchCustom',
  177. field: 'yAxis_grid_line_style_lineDash',
  178. optionField: 'yAxis.grid.line.style.lineDash',
  179. value: 0,
  180. active: 5,
  181. inactive: 0,
  182. tabName: 'custom',
  183. groupName: 'grid'
  184. },
  185. {
  186. label: '宽度',
  187. type: 'inputNumber',
  188. field: 'yAxis_grid_line_style_lineWidth',
  189. optionField: 'yAxis.grid.line.style.lineWidth',
  190. value: 1,
  191. tabName: 'custom',
  192. groupName: 'grid'
  193. },
  194. {
  195. label: '颜色',
  196. type: 'colorPicker',
  197. field: 'yAxis_grid_line_style_stroke',
  198. optionField: 'yAxis.grid.line.style.stroke',
  199. value: '#d0d0d0',
  200. tabName: 'custom',
  201. groupName: 'grid'
  202. },
  203. // 图例 legend
  204. // X轴 xAxis
  205. {
  206. label: '标题',
  207. type: 'input',
  208. field: 'xAxis_title_text',
  209. optionField: 'xAxis.title.text',
  210. value: '',
  211. tabName: 'custom',
  212. groupName: 'xAxis'
  213. },
  214. {
  215. label: '标题位置',
  216. type: 'select',
  217. field: 'xAxis_title_position',
  218. optionField: 'xAxis.title.position',
  219. value: 'end',
  220. tabName: 'custom',
  221. options: [
  222. {
  223. label: '左',
  224. value: 'start'
  225. },
  226. {
  227. label: '中',
  228. value: 'center'
  229. },
  230. {
  231. label: '右',
  232. value: 'end'
  233. }],
  234. groupName: 'xAxis'
  235. },
  236. {
  237. label: '标题字体大小',
  238. type: 'inputNumber',
  239. field: 'xAxis_title_style_fontSize',
  240. optionField: 'xAxis.title.style.fontSize',
  241. value: 12,
  242. tabName: 'custom',
  243. groupName: 'xAxis'
  244. },
  245. {
  246. label: '标题颜色',
  247. type: 'colorPicker',
  248. field: 'xAxis_title_style_fill',
  249. optionField: 'xAxis.title.style.fill',
  250. // 是否多选
  251. multiple: false,
  252. value: '#8C8C8C',
  253. tabName: 'custom',
  254. groupName: 'xAxis'
  255. },
  256. {
  257. label: '标签大小',
  258. type: 'inputNumber',
  259. field: 'xAxis_label_style_fontSize',
  260. optionField: 'xAxis.label.style.fontSize',
  261. value: 12,
  262. tabName: 'custom',
  263. groupName: 'xAxis'
  264. },
  265. {
  266. label: '标签颜色',
  267. type: 'colorPicker',
  268. field: 'xAxis_label_style_fill',
  269. optionField: 'xAxis.label.style.fill',
  270. // 是否多选
  271. multiple: false,
  272. value: '#8C8C8C',
  273. tabName: 'custom',
  274. groupName: 'xAxis'
  275. },
  276. {
  277. label: '轴线宽度',
  278. type: 'inputNumber',
  279. field: 'xAxis_line_style_lineWidth',
  280. optionField: 'xAxis.line.style.lineWidth',
  281. value: 1,
  282. tabName: 'custom',
  283. groupName: 'xAxis'
  284. },
  285. {
  286. label: '轴线颜色',
  287. type: 'colorPicker',
  288. field: 'xAxis_line_style_stroke',
  289. optionField: 'xAxis.line.style.stroke',
  290. // 是否多选
  291. multiple: false,
  292. value: '#d0d0d0',
  293. tabName: 'custom',
  294. groupName: 'xAxis'
  295. },
  296. {
  297. label: '刻度线宽度',
  298. type: 'inputNumber',
  299. field: 'xAxis_tickLine_style_lineWidth',
  300. optionField: 'xAxis.tickLine.style.lineWidth',
  301. value: 1,
  302. tabName: 'custom',
  303. groupName: 'xAxis'
  304. },
  305. {
  306. label: '刻度线颜色',
  307. type: 'colorPicker',
  308. field: 'xAxis_tickLine_style_stroke',
  309. optionField: 'xAxis.tickLine.style.stroke',
  310. // 是否多选
  311. multiple: false,
  312. value: '#d0d0d0',
  313. tabName: 'custom',
  314. groupName: 'xAxis'
  315. },
  316. {
  317. label: '标签过多时旋转',
  318. type: 'switch',
  319. field: 'xAxis_label_autoRotate',
  320. optionField: 'xAxis.label.autoRotate',
  321. value: false,
  322. tabName: 'custom',
  323. groupName: 'xAxis'
  324. },
  325. {
  326. label: '标签过多时隐藏',
  327. type: 'switch',
  328. field: 'xAxis_label_autoHide',
  329. optionField: 'xAxis.label.autoHide',
  330. value: false,
  331. tabName: 'custom',
  332. groupName: 'xAxis'
  333. },
  334. {
  335. label: '标签过长时省略',
  336. type: 'switch',
  337. field: 'xAxis_label_autoEllipsis',
  338. optionField: 'xAxis.label.autoEllipsis',
  339. value: false,
  340. tabName: 'custom',
  341. groupName: 'xAxis'
  342. },
  343. // Y轴 yAxis
  344. {
  345. label: '标题',
  346. type: 'input',
  347. field: 'yAxis_title_text',
  348. optionField: 'yAxis.title.text',
  349. value: '',
  350. tabName: 'custom',
  351. groupName: 'yAxis'
  352. },
  353. {
  354. label: '标题位置',
  355. type: 'select',
  356. field: 'yAxis_title_position',
  357. optionField: 'yAxis.title.position',
  358. value: 'end',
  359. tabName: 'custom',
  360. options: [
  361. {
  362. label: '上',
  363. value: 'end'
  364. },
  365. {
  366. label: '中',
  367. value: 'center'
  368. },
  369. {
  370. label: '下',
  371. value: 'start'
  372. }],
  373. groupName: 'yAxis'
  374. },
  375. {
  376. label: '标题字体大小',
  377. type: 'inputNumber',
  378. field: 'yAxis_title_style_fontSize',
  379. optionField: 'yAxis.title.style.fontSize',
  380. value: 12,
  381. tabName: 'custom',
  382. groupName: 'yAxis'
  383. },
  384. {
  385. label: '标题颜色',
  386. type: 'colorPicker',
  387. field: 'yAxis_title_style_fill',
  388. optionField: 'yAxis.title.style.fill',
  389. // 是否多选
  390. multiple: false,
  391. value: '#8C8C8C',
  392. tabName: 'custom',
  393. groupName: 'yAxis'
  394. },
  395. {
  396. label: '显示标签',
  397. type: 'switchNumber',
  398. field: 'yAxis_label_style_opacity',
  399. optionField: 'yAxis.label.style.opacity',
  400. value: 1,
  401. tabName: 'custom',
  402. groupName: 'yAxis'
  403. },
  404. {
  405. label: '标签字体大小',
  406. type: 'inputNumber',
  407. field: 'yAxis_label_style_fontSize',
  408. optionField: 'yAxis.label.style.fontSize',
  409. value: 12,
  410. tabName: 'custom',
  411. groupName: 'yAxis'
  412. },
  413. {
  414. label: '标签字体颜色',
  415. type: 'colorPicker',
  416. field: 'yAxis_label_style_fill',
  417. optionField: 'yAxis.label.style.fill',
  418. // 是否多选
  419. multiple: false,
  420. value: '#8C8C8C',
  421. tabName: 'custom',
  422. groupName: 'yAxis'
  423. },
  424. {
  425. label: '轴线宽度',
  426. type: 'inputNumber',
  427. field: 'yAxis_line_lineWidth',
  428. optionField: 'yAxis.line.style.lineWidth',
  429. value: 0,
  430. tabName: 'custom',
  431. groupName: 'yAxis'
  432. },
  433. {
  434. label: '轴线颜色',
  435. type: 'colorPicker',
  436. field: 'yAxis_line_stroke',
  437. optionField: 'yAxis.line.style.stroke',
  438. // 是否多选
  439. multiple: false,
  440. value: '#d0d0d0',
  441. tabName: 'custom',
  442. groupName: 'yAxis'
  443. },
  444. // 边距 padding
  445. {
  446. label: '图表边距',
  447. type: 'padding',
  448. field: 'appendPadding',
  449. optionField: 'appendPadding',
  450. value: [16, 16, 16, 16],
  451. tabName: 'custom',
  452. groupName: 'padding'
  453. }
  454. ]
  455. // 模拟数据
  456. const data = [
  457. { Date: '2010-01', scales: 1998 },
  458. { Date: '2010-02', scales: 1850 },
  459. { Date: '2010-03', scales: 1720 },
  460. { Date: '2010-04', scales: 1818 },
  461. { Date: '2010-05', scales: 1920 },
  462. { Date: '2010-06', scales: 1802 },
  463. { Date: '2010-07', scales: 1945 },
  464. { Date: '2010-08', scales: 1856 },
  465. { Date: '2010-09', scales: 2107 },
  466. { Date: '2010-10', scales: 2140 }
  467. ]
  468. // 配置处理脚本
  469. const optionHandler = 'option.yAxis.grid.line.style.lineDash = [4,setting.find(settingItem=>settingItem.field === \'yAxis_grid_line_style_lineDash\').value]'
  470. // 数据处理脚本
  471. const dataHandler = ''
  472. // 图表配置 new Line('domName', option)
  473. const option = {
  474. // 数据将要放入到哪个字段中
  475. dataKey: 'data',
  476. data,
  477. color: '',
  478. appendPadding: [16, 16, 16, 16], // 设置图标的边距
  479. xField: 'Date',
  480. yField: 'scales',
  481. smooth: false,
  482. lineStyle: {
  483. lineWidth: 2,
  484. stroke: 'l(0) 0:#5F92F9 1:#62FF00'
  485. },
  486. label: {
  487. style: {
  488. fill: '#fff',
  489. opacity: 0,
  490. fontSize: 12
  491. }
  492. },
  493. point: {
  494. size: 2,
  495. shape: 'diamond',
  496. style: {
  497. fill: 'red',
  498. stroke: '#5B8FF9',
  499. lineWidth: 2
  500. }
  501. },
  502. tooltip: { showMarkers: false },
  503. state: {
  504. active: {
  505. style: {
  506. shadowBlur: 4,
  507. stroke: '#000',
  508. fill: 'red'
  509. }
  510. }
  511. },
  512. xAxis: {
  513. title: {
  514. text: '',
  515. position: 'end',
  516. style: {
  517. fill: '#8C8C8C',
  518. fontSize: 12
  519. }
  520. },
  521. label: {
  522. autoRotate: false,
  523. autoHide: false,
  524. autoEllipsis: true,
  525. style: {
  526. fill: '#8C8C8C',
  527. fontSize: 12
  528. }
  529. },
  530. line: {
  531. style: {
  532. stroke: '#d0d0d0',
  533. lineWidth: 1
  534. }
  535. },
  536. tickLine: {
  537. style: {
  538. stroke: '#d0d0d0',
  539. lineWidth: 1
  540. }
  541. }
  542. },
  543. yAxis: {
  544. title: {
  545. text: '',
  546. position: 'end',
  547. autoRotate: false,
  548. // rotation: Math.PI / 2,
  549. style: {
  550. fill: '#8C8C8C',
  551. fontSize: 12
  552. }
  553. },
  554. grid: {
  555. line: {
  556. style: {
  557. stroke: '#d0d0d0',
  558. lineWidth: 1,
  559. lineDash: [4, 5],
  560. strokeOpacity: 0.7
  561. }
  562. }
  563. },
  564. label: {
  565. style: {
  566. fill: '#8C8C8C',
  567. fontSize: 12,
  568. opacity: 1
  569. }
  570. },
  571. line: {
  572. style: {
  573. stroke: '#d0d0d0',
  574. lineWidth: 0
  575. }
  576. }
  577. }
  578. }
  579. export default {
  580. category,
  581. version,
  582. title,
  583. chartType,
  584. name,
  585. option,
  586. setting,
  587. dataHandler,
  588. optionHandler
  589. }