85a35bb82c5ac1853e8aa450776803edbea1fed2.svn-base 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import i18n from '@/i18n'
  2. import { sqlFunc } from './configs'
  3. function dataTransfer(data, schema) {
  4. const chartData = data.map(item => {
  5. const dataItem = {}
  6. schema.forEach(column => {
  7. // hasxAxis = hasxAxis || column.asxAxis
  8. if (column.calculFunc) {
  9. column.lable = `${column.Column}(${sqlFunc[column.calculFunc]})`
  10. } else {
  11. column.lable = `${column.Column}`
  12. }
  13. column.name = column.Column
  14. column.asxAxis = column.isDimension
  15. dataItem[column.Column] = item[column.Column]
  16. })
  17. return dataItem
  18. })
  19. return chartData
  20. }
  21. const chartTypeList = [
  22. {
  23. name: i18n.t('chartType.table'),
  24. icon: 'chart_table',
  25. type: 'table',
  26. matchRule: {
  27. desc: i18n.t('chartType.tableDesc'),
  28. isUsable(dimensions, calculs) {
  29. return true
  30. }
  31. },
  32. componentName: 'DataTable',
  33. dataTransfer(data, schema) {
  34. const chartData = data.map(item => {
  35. const dataItem = {}
  36. schema.forEach(column => {
  37. if (column.calculFunc) {
  38. column.name = `${column.Column}(${sqlFunc[column.calculFunc]})`
  39. } else {
  40. column.name = `${column.Column}`
  41. }
  42. dataItem[column.Column] = item[column.Column]
  43. })
  44. return dataItem
  45. })
  46. return chartData
  47. }
  48. },
  49. {
  50. name: i18n.t('chartType.line'),
  51. icon: 'chart_line',
  52. type: 'line',
  53. matchRule: {
  54. desc: i18n.t('chartType.lineDesc'),
  55. isUsable(dimensions, calculs) {
  56. return (dimensions.length === 1 || dimensions.length === 2) && (calculs.length >= 1)
  57. }
  58. },
  59. componentName: 'lineChart', dataTransfer
  60. },
  61. {
  62. name: i18n.t('chartType.bar'),
  63. icon: 'chart_bar',
  64. type: 'bar',
  65. matchRule: {
  66. desc: i18n.t('chartType.barDesc'),
  67. isUsable(dimensions, calculs) {
  68. return (dimensions.length === 1 || dimensions.length === 2) && (calculs.length >= 1)
  69. }
  70. },
  71. componentName: 'BarChart',
  72. dataTransfer
  73. },
  74. {
  75. name: i18n.t('chartType.stackBar'),
  76. icon: 'stack_bar',
  77. type: 'stackBar',
  78. matchRule: {
  79. desc: i18n.t('chartType.stackBarDesc'),
  80. isUsable(dimensions, calculs) {
  81. return (dimensions.length === 1 || dimensions.length === 2) && (calculs.length >= 2)
  82. }
  83. },
  84. componentName: 'StackBarChart',
  85. dataTransfer
  86. },
  87. {
  88. name: i18n.t('chartType.pie'),
  89. icon: 'chart_pie',
  90. type: 'pie',
  91. matchRule: {
  92. desc: i18n.t('chartType.pieDesc'),
  93. isUsable(dimensions, calculs) {
  94. return (dimensions.length === 1 && calculs.length === 1) || (dimensions.length === 0 && calculs.length >= 1)
  95. }
  96. },
  97. componentName: 'PieChart',
  98. dataTransfer
  99. },
  100. {
  101. name: i18n.t('chartType.horizontalBar'),
  102. icon: 'horizontal_bar',
  103. type: 'horizontalBar',
  104. matchRule: {
  105. desc: i18n.t('chartType.horizontalBarDesc'),
  106. isUsable(dimensions, calculs) {
  107. return (dimensions.length === 1 || dimensions.length === 2) && (calculs.length >= 1)
  108. }
  109. },
  110. componentName: 'HorizontalBar',
  111. dataTransfer
  112. },
  113. {
  114. name: '柱线图:',
  115. icon: 'linebar_chart',
  116. type: 'BarLineChart',
  117. matchRule: {
  118. desc: '1或2个纬度;1或多个数值',
  119. isUsable(dimensions, calculs) {
  120. return (dimensions.length === 1 || dimensions.length === 2) && (calculs.length >= 1)
  121. }
  122. },
  123. componentName: 'BarLineChart',
  124. dataTransfer
  125. },
  126. ]
  127. export default chartTypeList