Bar.vue 938 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div :style="{ padding: '0 0 32px 32px' }">
  3. <h4 :style="{ marginBottom: '20px' }">{{ title }}</h4>
  4. <v-chart
  5. height="254"
  6. :data="data"
  7. :forceFit="true"
  8. :padding="['auto', 'auto', '40', '50']">
  9. <v-tooltip />
  10. <v-axis />
  11. <v-bar position="x*y"/>
  12. </v-chart>
  13. </div>
  14. </template>
  15. <script>
  16. const data = []
  17. for (let i = 0; i < 12; i += 1) {
  18. data.push({
  19. x: `${i + 1}月`,
  20. y: Math.floor(Math.random() * 1000) + 200
  21. })
  22. }
  23. const tooltip = [
  24. 'x*y',
  25. (x, y) => ({
  26. name: x,
  27. value: y
  28. })
  29. ]
  30. const scale = [{
  31. dataKey: 'x',
  32. min: 2
  33. }, {
  34. dataKey: 'y',
  35. title: '时间',
  36. min: 1,
  37. max: 22
  38. }]
  39. export default {
  40. name: "Bar",
  41. props: {
  42. title: {
  43. type: String,
  44. default: ''
  45. }
  46. },
  47. data () {
  48. return {
  49. data,
  50. scale,
  51. tooltip
  52. }
  53. }
  54. }
  55. </script>