Bar.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div :style="{ padding: '0 0 32px 32px' }">
  3. <h3 :style="{ marginBottom: '20px' }">{{ title }}</h3>
  4. <v-chart :forceFit="true" :height="height" :data="dataSource" :scale="scale" :padding="padding">
  5. <v-tooltip />
  6. <v-axis />
  7. <v-bar position="x*y" :color="color" />
  8. </v-chart>
  9. </div>
  10. </template>
  11. <script>
  12. import { triggerWindowResizeEvent } from '@/utils/util'
  13. import { DEFAULT_COLOR } from '@/store/mutation-types'
  14. import Vue from 'vue'
  15. export default {
  16. name: 'Bar',
  17. props: {
  18. dataSource: {
  19. type: Array,
  20. required: true,
  21. },
  22. yaxisText: {
  23. type: String,
  24. default: 'y',
  25. },
  26. title: {
  27. type: String,
  28. default: '',
  29. },
  30. height: {
  31. type: Number,
  32. default: 254,
  33. },
  34. },
  35. data() {
  36. return {
  37. padding: ['auto', 'auto', '40', '50'],
  38. color: Vue.ls.get(DEFAULT_COLOR),
  39. }
  40. },
  41. computed: {
  42. scale() {
  43. return [
  44. {
  45. dataKey: 'y',
  46. alias: this.yaxisText,
  47. },
  48. ]
  49. },
  50. },
  51. mounted() {
  52. triggerWindowResizeEvent()
  53. },
  54. }
  55. </script>