e6f7b86eddbae8f6ad6bad396b27c0f6faf4df90.svn-base 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <div class="antv-chart-mini">
  3. <div class="chart-wrapper" :style="{ height: 46 }">
  4. <v-chart :force-fit="true" :height="height" :data="data" :scale="scale" :padding="[36, 0, 18, 0]">
  5. <v-tooltip/>
  6. <v-smooth-area position="x*y"/>
  7. </v-chart>
  8. </div>
  9. </div>
  10. </template>
  11. <script>
  12. import moment from 'dayjs'
  13. const sourceData = []
  14. const beginDay = new Date().getTime()
  15. for (let i = 0; i < 10; i++) {
  16. sourceData.push({
  17. x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY'),
  18. y: Math.round(Math.random() * 10)
  19. })
  20. }
  21. export default {
  22. name: 'MiniArea',
  23. props: {
  24. dataSource: {
  25. type: Array,
  26. default: () => []
  27. },
  28. // x 轴别名
  29. x: {
  30. type: String,
  31. default: 'x'
  32. },
  33. // y 轴别名
  34. y: {
  35. type: String,
  36. default: 'y'
  37. }
  38. },
  39. data() {
  40. return {
  41. data: [],
  42. height: 100
  43. }
  44. },
  45. computed: {
  46. scale() {
  47. return [
  48. { dataKey: 'x', title: this.x, alias: this.x },
  49. { dataKey: 'y', title: this.y, alias: this.y }
  50. ]
  51. }
  52. },
  53. created() {
  54. if (this.dataSource.length === 0) {
  55. this.data = sourceData
  56. } else {
  57. this.data = this.dataSource
  58. }
  59. }
  60. }
  61. </script>
  62. <style lang="less" scoped>
  63. @import "chart";
  64. </style>