828e3aec0b636b85d8b4a3888fc0a811f63772fc.svn-base 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <div :style="{'width':width==null?'auto':width+'px'}">
  3. <v-chart :forceFit="width==null" :height="height" :data="data" padding="0">
  4. <v-tooltip/>
  5. <v-bar position="x*y"/>
  6. </v-chart>
  7. </div>
  8. </template>
  9. <script>
  10. import moment from 'dayjs'
  11. const sourceData = []
  12. const beginDay = new Date().getTime()
  13. for (let i = 0; i < 10; i++) {
  14. sourceData.push({
  15. x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'),
  16. y: Math.round(Math.random() * 10)
  17. })
  18. }
  19. const tooltip = [
  20. 'x*y',
  21. (x, y) => ({
  22. name: x,
  23. value: y
  24. })
  25. ]
  26. const scale = [{
  27. dataKey: 'x',
  28. min: 2
  29. }, {
  30. dataKey: 'y',
  31. title: '时间',
  32. min: 1,
  33. max: 30
  34. }]
  35. export default {
  36. name: 'MiniBar',
  37. props: {
  38. dataSource: {
  39. type: Array,
  40. default: () => []
  41. },
  42. width: {
  43. type: Number,
  44. default: null
  45. },
  46. height: {
  47. type: Number,
  48. default: 200
  49. }
  50. },
  51. created() {
  52. if (this.dataSource.length === 0) {
  53. this.data = sourceData
  54. } else {
  55. this.data = this.dataSource
  56. }
  57. },
  58. data() {
  59. return {
  60. tooltip,
  61. data: [],
  62. scale
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="less" scoped>
  68. @import "chart";
  69. </style>