ed4f9606a53fabea240bcc6922979fe9aba75038.svn-base 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div :style="{ padding: '0 0 32px 32px' }">
  3. <h4 :style="{ marginBottom: '0px' }">{{ title }}</h4>
  4. <v-chart :data="data" :height="height" :force-fit="true" :scale="scale" :onClick="handleClick">
  5. <v-tooltip/>
  6. <v-axis/>
  7. <v-legend/>
  8. <v-bar position="x*y" color="type" :adjust="adjust"/>
  9. </v-chart>
  10. </div>
  11. </template>
  12. <script>
  13. import { DataSet } from '@antv/data-set'
  14. import { ChartEventMixins } from './mixins/ChartMixins'
  15. export default {
  16. name: 'BarMultid',
  17. mixins: [ChartEventMixins],
  18. props: {
  19. title: {
  20. type: String,
  21. default: ''
  22. },
  23. dataSource: {
  24. type: Array,
  25. default: () => [
  26. { type: 'Jeecg', 'Jan.': 18.9, 'Feb.': 28.8, 'Mar.': 39.3, 'Apr.': 81.4, 'May': 47, 'Jun.': 20.3, 'Jul.': 24, 'Aug.': 35.6 },
  27. { type: 'Jeebt', 'Jan.': 12.4, 'Feb.': 23.2, 'Mar.': 34.5, 'Apr.': 99.7, 'May': 52.6, 'Jun.': 35.5, 'Jul.': 37.4, 'Aug.': 42.4 }
  28. ]
  29. },
  30. fields: {
  31. type: Array,
  32. default: () => ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'Jun.', 'Jul.', 'Aug.']
  33. },
  34. // 别名,需要的格式:[{field:'name',alias:'姓名'}, {field:'sex',alias:'性别'}]
  35. aliases: {
  36. type: Array,
  37. default: () => []
  38. },
  39. height: {
  40. type: Number,
  41. default: 400
  42. }
  43. },
  44. data() {
  45. return {
  46. adjust: [{
  47. type: 'dodge',
  48. marginRatio: 1 / 32
  49. }]
  50. }
  51. },
  52. computed: {
  53. data() {
  54. const dv = new DataSet.View().source(this.dataSource)
  55. dv.transform({
  56. type: 'fold',
  57. fields: this.fields,
  58. key: 'x',
  59. value: 'y'
  60. })
  61. // bar 使用不了 - 和 / 所以替换下
  62. let rows = dv.rows.map(row => {
  63. if (typeof row.x === 'string') {
  64. row.x = row.x.replace(/[-/]/g, '_')
  65. }
  66. return row
  67. })
  68. // 替换别名
  69. rows.forEach(row => {
  70. for (let item of this.aliases) {
  71. if (item.field === row.type) {
  72. row.type = item.alias
  73. break
  74. }
  75. }
  76. })
  77. return rows
  78. },
  79. scale() {
  80. return [
  81. {
  82. type: 'cat',
  83. dataKey: 'x'
  84. }
  85. ]
  86. }
  87. }
  88. }
  89. </script>
  90. <style scoped>
  91. </style>