Blame view

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

<script>
肖超群 authored
13
import moment from 'dayjs'
肖超群 authored
14
肖超群 authored
15
16
const sourceData = []
const beginDay = new Date().getTime()
肖超群 authored
17
肖超群 authored
18
19
20
21
22
23
for (let i = 0; i < 10; i++) {
  sourceData.push({
    x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'),
    y: Math.round(Math.random() * 10)
  })
}
肖超群 authored
24
肖超群 authored
25
26
27
28
29
30
export default {
  name: 'MiniArea',
  props: {
    dataSource: {
      type: Array,
      default: () => []
肖超群 authored
31
    },
肖超群 authored
32
33
34
35
    // x 轴别名
    x: {
      type: String,
      default: 'x'
肖超群 authored
36
    },
肖超群 authored
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
    // y 轴别名
    y: {
      type: String,
      default: 'y'
    }
  },
  data() {
    return {
      data: [],
      height: 100
    }
  },
  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
肖超群 authored
62
63
    }
  }
肖超群 authored
64
}
肖超群 authored
65
66
67
</script>

<style lang="less" scoped>
肖超群 authored
68
@import "chart";
肖超群 authored
69
</style>