5afd0cfcb26570d658e10b869e4e6225cb243900.svn-base 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. console.log('data============', data)
  35. console.log('schema============', schema)
  36. const chartData = data.map(item => {
  37. const dataItem = {}
  38. schema.forEach(column => {
  39. if (column.calculFunc) {
  40. column.name = `${column.Column}(${sqlFunc[column.calculFunc]})`
  41. } else {
  42. column.name = `${column.Column}`
  43. }
  44. dataItem[column.Column] = item[column.Column]
  45. })
  46. return dataItem
  47. })
  48. console.log('chartData============', chartData)
  49. return chartData
  50. }
  51. },
  52. {
  53. name: i18n.t('chartType.line'),
  54. icon: 'chart_line',
  55. type: 'line',
  56. matchRule: {
  57. desc: i18n.t('chartType.lineDesc'),
  58. isUsable(dimensions, calculs) {
  59. return (dimensions.length === 1 || dimensions.length === 2) && (calculs.length >= 1)
  60. }
  61. },
  62. componentName: 'lineChart', dataTransfer
  63. },
  64. {
  65. name: i18n.t('chartType.bar'),
  66. icon: 'chart_bar',
  67. type: 'bar',
  68. matchRule: {
  69. desc: i18n.t('chartType.barDesc'),
  70. isUsable(dimensions, calculs) {
  71. return (dimensions.length === 1 || dimensions.length === 2) && (calculs.length >= 1)
  72. }
  73. },
  74. componentName: 'BarChart',
  75. dataTransfer
  76. },
  77. {
  78. name: i18n.t('chartType.stackBar'),
  79. icon: 'stack_bar',
  80. type: 'stackBar',
  81. matchRule: {
  82. desc: i18n.t('chartType.stackBarDesc'),
  83. isUsable(dimensions, calculs) {
  84. return (dimensions.length === 1 || dimensions.length === 2) && (calculs.length >= 2)
  85. }
  86. },
  87. componentName: 'StackBarChart',
  88. dataTransfer
  89. },
  90. {
  91. name: i18n.t('chartType.pie'),
  92. icon: 'chart_pie',
  93. type: 'pie',
  94. matchRule: {
  95. desc: i18n.t('chartType.pieDesc'),
  96. isUsable(dimensions, calculs) {
  97. return (dimensions.length === 1 && calculs.length === 1) || (dimensions.length === 0 && calculs.length >= 1)
  98. }
  99. },
  100. componentName: 'PieChart',
  101. dataTransfer
  102. },
  103. {
  104. name: i18n.t('chartType.horizontalBar'),
  105. icon: 'horizontal_bar',
  106. type: 'horizontalBar',
  107. matchRule: {
  108. desc: i18n.t('chartType.horizontalBarDesc'),
  109. isUsable(dimensions, calculs) {
  110. return (dimensions.length === 1 || dimensions.length === 2) && (calculs.length >= 1)
  111. }
  112. },
  113. componentName: 'HorizontalBar',
  114. dataTransfer
  115. },
  116. {
  117. name: '柱线图:',
  118. icon: 'barline_chart',
  119. type: 'BarLineChart',
  120. matchRule: {
  121. desc: '1个纬度多个数值',
  122. isUsable(dimensions, calculs) {
  123. return (dimensions.length === 1) && (calculs.length >= 1)
  124. }
  125. },
  126. componentName: 'BarLineChart',
  127. dataTransfer
  128. },
  129. {
  130. name: '线柱图:',
  131. icon: 'linebar_chart',
  132. type: 'LineBarChart',
  133. matchRule: {
  134. desc: '1个纬度多个数值',
  135. isUsable(dimensions, calculs) {
  136. return (dimensions.length === 1) && (calculs.length >= 1)
  137. }
  138. },
  139. componentName: 'LineBarChart',
  140. dataTransfer
  141. },
  142. ]
  143. export default chartTypeList