基础漏斗图.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. // 配置版本号
  2. const version = '2023071001'
  3. // 分类
  4. const category = 'Funnel'
  5. // 标题
  6. const title = '基础漏斗图'
  7. // 类别, new Line()
  8. const chartType = 'Funnel'
  9. // 用于标识,唯一,title的中文转拼音
  10. const name = 'JiChuLouDouTu'
  11. // 右侧配置项
  12. const setting = [
  13. {
  14. label: '维度',
  15. // 设置组件类型, select / input / colorPicker
  16. type: 'select',
  17. // 字段
  18. field: 'xField',
  19. optionField: 'xField', // 对应options中的字段
  20. // 是否多选
  21. multiple: false,
  22. // 绑定的值
  23. value: '',
  24. // tab页。 data: 数据, custom: 自定义
  25. tabName: 'data'
  26. },
  27. {
  28. label: '指标',
  29. // 设置组件类型
  30. type: 'select',
  31. // 字段
  32. field: 'yField',
  33. // 对应options中的字段
  34. optionField: 'yField',
  35. // 是否多选
  36. multiple: false,
  37. value: '',
  38. tabName: 'data'
  39. },
  40. /** 样式配置 **/
  41. // 图表 graph
  42. // {
  43. // label: '漏斗形状',
  44. // type: 'select', // 设置组件类型
  45. // field: 'shape', // 字段
  46. // optionField: 'shape', // 对应options中的字段
  47. // value: 'funnel',
  48. // tabName: 'custom',
  49. // options: [
  50. // {
  51. // label: '默认',
  52. // value: 'funnel'
  53. // },
  54. // {
  55. // label: '金字塔',
  56. // value: 'pyramid'
  57. // }
  58. // ]
  59. // },
  60. {
  61. label: '是否映射为动态高度',
  62. type: 'switch', // 设置组件类型
  63. field: 'dynamicHeight', // 字段
  64. optionField: 'dynamicHeight', // 对应options中的字段
  65. value: false,
  66. active: true,
  67. inactive: false,
  68. tabName: 'custom',
  69. groupName: 'graph'
  70. },
  71. {
  72. label: '方向',
  73. type: 'select', // 设置组件类型
  74. field: 'isTransposed', // 字段
  75. optionField: 'isTransposed', // 对应options中的字段
  76. value: false,
  77. active: true,
  78. inactive: false,
  79. tabName: 'custom',
  80. options: [
  81. {
  82. label: '竖向',
  83. value: false
  84. },
  85. {
  86. label: '横向',
  87. value: true
  88. }
  89. ],
  90. groupName: 'graph'
  91. },
  92. {
  93. label: '标签文本',
  94. type: 'input', // 设置组件类型
  95. field: 'conversionTagName', // 字段
  96. optionField: 'conversionTagName', // 对应options中的字段
  97. value: '转化率',
  98. tabName: 'custom',
  99. groupName: 'graph'
  100. },
  101. {
  102. label: '标签颜色',
  103. // 设置组件类型
  104. type: 'colorPicker',
  105. // 字段
  106. field: 'conversionTag_style_fill',
  107. // 对应options中的字段
  108. optionField: 'conversionTag.style.fill',
  109. // 绑定的值
  110. value: '#8c8c8c',
  111. tabName: 'custom',
  112. groupName: 'graph'
  113. },
  114. {
  115. label: '颜色',
  116. // 设置组件类型
  117. type: 'colorSelect',
  118. // 字段
  119. field: 'color',
  120. // 对应options中的字段
  121. optionField: 'color',
  122. value: ['#5B8FF9', '#61DDAA', '#5D7092', '#F6BD16', '#6F5EF9', '#6DC8EC', '#945FB9', '#FF9845', '#1E9493', '#FF99C3'],
  123. tabName: 'custom',
  124. groupName: 'graph'
  125. },
  126. {
  127. label: '数据标签颜色',
  128. type: 'colorPicker', // 设置组件类型
  129. field: 'label_style_fill', // 字段
  130. optionField: 'label.style.fill', // 对应options中的字段
  131. value: '#ffffff',
  132. tabName: 'custom',
  133. groupName: 'graph'
  134. },
  135. {
  136. label: '数据标签大小',
  137. // 设置组件类型
  138. type: 'inputNumber',
  139. // 字段
  140. field: 'label_style_fontSize',
  141. // 对应options中的字段
  142. optionField: 'label.style.fontSize',
  143. value: 12,
  144. tabName: 'custom',
  145. groupName: 'graph'
  146. },
  147. // 图例 legend
  148. {
  149. label: '显示',
  150. type: 'switch', // 设置组件类型
  151. field: 'legendEnable', // 字段
  152. optionField: 'legendEnable', // 对应options中的字段
  153. value: false,
  154. active: true,
  155. inactive: false,
  156. tabName: 'custom',
  157. groupName: 'legend'
  158. },
  159. {
  160. label: '位置',
  161. type: 'select', // 设置组件类型
  162. field: 'legendPosition', // 字段
  163. optionField: 'legendPosition', // 对应options中的字段
  164. // 是否多选
  165. multiple: false,
  166. value: 'top',
  167. tabName: 'custom',
  168. options: [
  169. { label: '顶部', value: 'top' },
  170. { label: '左上角', value: 'top-left' },
  171. { label: '右上角', value: 'top-right' },
  172. { label: '左侧', value: 'left' },
  173. // { label: '左上方', value: 'left-top' },
  174. // { label: '左下方', value: 'left-bottom' },
  175. { label: '右侧', value: 'right' },
  176. // { label: '右上方', value: 'right-top' },
  177. // { label: '右下方', value: 'right-bottom' },
  178. { label: '底部', value: 'bottom' },
  179. { label: '左下角', value: 'bottom-left' },
  180. { label: '右下角', value: 'bottom-right' }
  181. ],
  182. groupName: 'legend'
  183. },
  184. {
  185. label: '字体大小',
  186. type: 'inputNumber',
  187. field: 'legendItemName_style_fontSize',
  188. optionField: 'legendItemName.style.fontSize',
  189. value: 12,
  190. tabName: 'custom',
  191. groupName: 'legend'
  192. },
  193. {
  194. label: '字体权重',
  195. type: 'inputNumber',
  196. step: 100,
  197. max: 900,
  198. field: 'legendItemName_style_fontWeight',
  199. optionField: 'legendItemName.style.fontWeight',
  200. value: 400,
  201. tabName: 'custom',
  202. groupName: 'legend'
  203. },
  204. {
  205. label: '字体颜色',
  206. type: 'colorPicker',
  207. field: 'legendItemName_style_fill',
  208. optionField: 'legendItemName.style.fill',
  209. value: '#595959',
  210. tabName: 'custom',
  211. groupName: 'legend'
  212. },
  213. // 边距 padding
  214. {
  215. label: '图表边距',
  216. type: 'padding', // 设置组件类型
  217. field: 'appendPadding', // 字段
  218. optionField: 'appendPadding', // 对应options中的字段
  219. value: [16, 16, 16, 16],
  220. tabName: 'custom',
  221. groupName: 'padding'
  222. }
  223. ]
  224. // 模拟数据
  225. const data = [
  226. { stage: '简历筛选', number: 253 },
  227. { stage: '初试人数', number: 151 },
  228. { stage: '复试人数', number: 113 },
  229. { stage: '录取人数', number: 87 },
  230. { stage: '入职人数', number: 59 }
  231. ]
  232. // 配置处理脚本
  233. const optionHandler = `option.legend = option.legendEnable ? {position: option.legendPosition}: false;
  234. window.conversionTagName = option.conversionTagName
  235. option.conversionTag.formatter = (datum) => {
  236. return window.conversionTagName + datum.$$percentage$$.toFixed(2) * 100 + '%'
  237. }
  238. if (option.legendEnable) {
  239. option.legend.itemName = option.legendItemName
  240. }
  241. `
  242. // 数据处理脚本
  243. const dataHandler = 'data = data.sort((a, b) => b[option.yField] - a[option.yField])'
  244. // 图表配置 new Line('domName', option)
  245. const option = {
  246. // 数据将要放入到哪个字段中
  247. dataKey: 'data',
  248. data,
  249. color: ['#5B8FF9', '#61DDAA', '#5D7092', '#F6BD16', '#6F5EF9', '#6DC8EC', '#945FB9', '#FF9845', '#1E9493', '#FF99C3'],
  250. appendPadding: [16, 16, 16, 16], // 设置图标的边距
  251. xField: 'stage',
  252. yField: 'number',
  253. dynamicHeight: false,
  254. isTransposed: false,
  255. legendEnable: false,
  256. legendLayout: 'vertical',
  257. legendPosition: 'top',
  258. legend: false,
  259. legendItemName: {
  260. style: {
  261. fill: '#595959',
  262. fontSize: 12,
  263. fontWeight: 400
  264. }
  265. },
  266. conversionTagName: '转化率',
  267. shape: 'funnel', // 漏斗的底部形状
  268. label: { // 图表内的数据标签
  269. // 配置样式
  270. style: {
  271. fill: '#ffffff',
  272. opacity: 1,
  273. fontSize: 12
  274. }
  275. },
  276. conversionTag: {
  277. offsetX: 10,
  278. offsetY: 0,
  279. style: {
  280. fill: '#8c8c8c',
  281. fontSize: 12
  282. },
  283. formatter: (datum) => {
  284. return '转化率' + datum.$$percentage$$.toFixed(2) * 100 + '%'
  285. }
  286. }
  287. }
  288. export default {
  289. category,
  290. version,
  291. title,
  292. chartType,
  293. name,
  294. option,
  295. setting,
  296. optionHandler,
  297. dataHandler
  298. }