Blame view

ant-design-vue-jeecg/src/components/chart/MiniArea.vue 1.37 KB
1
2
3
<template>
  <div class="antv-chart-mini">
    <div class="chart-wrapper" :style="{ height: 46 }">
4
5
6
      <v-chart :force-fit="true" :height="height" :data="data" :scale="scale" :padding="[36, 0, 18, 0]">
        <v-tooltip/>
        <v-smooth-area position="x*y"/>
7
8
9
10
11
12
13
      </v-chart>
    </div>
  </div>
</template>

<script>
  import moment from 'dayjs'
14
15

  const sourceData = []
16
17
18
  const beginDay = new Date().getTime()

  for (let i = 0; i < 10; i++) {
19
    sourceData.push({
20
21
22
23
24
25
      x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'),
      y: Math.round(Math.random() * 10)
    })
  }

  export default {
26
27
28
    name: 'MiniArea',
    props: {
      dataSource: {
29
        type: Array,
30
31
32
33
34
35
36
37
38
39
40
        default: () => []
      },
      // x 轴别名
      x: {
        type: String,
        default: 'x'
      },
      // y 轴别名
      y: {
        type: String,
        default: 'y'
41
42
      }
    },
43
    data() {
44
      return {
45
        data: [],
46
47
        height: 100
      }
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
    },
    computed: {
      scale() {
        return [
          { dataKey: 'x', title: this.x, alias: this.x },
          { dataKey: 'y', title: this.y, alias: this.y }
        ]
      }
    },
    created() {
      if (this.dataSource.length === 0) {
        this.data = sourceData
      } else {
        this.data = this.dataSource
      }
63
64
65
66
    }
  }
</script>
67
<style lang="less" scoped>
68
69
  @import "chart";
</style>