基础漏斗图.js 7.3 KB

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