85aca6afdb144350a733345d960066591c211bcb.svn-base 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. { name: i18n.t('chartType.table'),
  23. icon: 'chart_table',
  24. type: 'table',
  25. matchRule: {
  26. desc: i18n.t('chartType.tableDesc'),
  27. isUsable(dimensions, calculs) {
  28. return true
  29. }
  30. },
  31. componentName: 'DataTable',
  32. dataTransfer(data, schema) {
  33. const chartData = data.map(item => {
  34. const dataItem = {}
  35. schema.forEach(column => {
  36. if (column.calculFunc) {
  37. column.name = `${column.Column}(${sqlFunc[column.calculFunc]})`
  38. } else {
  39. column.name = `${column.Column}`
  40. }
  41. dataItem[column.Column] = item[column.Column]
  42. })
  43. return dataItem
  44. })
  45. return chartData
  46. }
  47. },
  48. { name: i18n.t('chartType.line'),
  49. icon: 'chart_line',
  50. type: 'line',
  51. matchRule: {
  52. desc: i18n.t('chartType.lineDesc'),
  53. isUsable(dimensions, calculs) {
  54. return (dimensions.length === 1 || dimensions.length === 2) && (calculs.length >= 1)
  55. }
  56. },
  57. componentName: 'lineChart', dataTransfer
  58. },
  59. { name: i18n.t('chartType.bar'),
  60. icon: 'chart_bar',
  61. type: 'bar',
  62. matchRule: {
  63. desc: i18n.t('chartType.barDesc'),
  64. isUsable(dimensions, calculs) {
  65. return (dimensions.length === 1 || dimensions.length === 2) && (calculs.length >= 1)
  66. }
  67. },
  68. componentName: 'BarChart',
  69. dataTransfer
  70. },
  71. { name: i18n.t('chartType.stackBar'),
  72. icon: 'stack_bar',
  73. type: 'stackBar',
  74. matchRule: {
  75. desc: i18n.t('chartType.stackBarDesc'),
  76. isUsable(dimensions, calculs) {
  77. return (dimensions.length === 1 || dimensions.length === 2) && (calculs.length >= 2)
  78. }
  79. },
  80. componentName: 'StackBarChart',
  81. dataTransfer
  82. },
  83. { name: i18n.t('chartType.pie'),
  84. icon: 'chart_pie',
  85. type: 'pie',
  86. matchRule: {
  87. desc: i18n.t('chartType.pieDesc'),
  88. isUsable(dimensions, calculs) {
  89. return (dimensions.length === 1 && calculs.length === 1) || (dimensions.length === 0 && calculs.length >= 1)
  90. }
  91. },
  92. componentName: 'PieChart',
  93. dataTransfer
  94. },
  95. { name: i18n.t('chartType.horizontalBar'),
  96. icon: 'horizontal_bar',
  97. type: 'horizontalBar',
  98. matchRule: {
  99. desc: i18n.t('chartType.horizontalBarDesc'),
  100. isUsable(dimensions, calculs) {
  101. return (dimensions.length === 1 || dimensions.length === 2) && (calculs.length >= 1)
  102. }
  103. },
  104. componentName: 'HorizontalBar',
  105. dataTransfer
  106. }
  107. ]
  108. export default chartTypeList