dbsd_kczx_java/ant-design-vue-jeecg/src/components/chart/MiniArea.vue

69 lines
1.4 KiB
Java
Raw Normal View History

2019-02-25 15:58:05 +08:00
<template>
<div class="antv-chart-mini">
<div class="chart-wrapper" :style="{ height: 46 }">
2019-04-14 16:20:04 +08:00
<v-chart :force-fit="true" :height="height" :data="data" :scale="scale" :padding="[36, 0, 18, 0]">
<v-tooltip/>
<v-smooth-area position="x*y"/>
2019-02-25 15:58:05 +08:00
</v-chart>
</div>
</div>
</template>
<script>
import moment from 'dayjs'
2019-04-14 16:20:04 +08:00
const sourceData = []
2019-02-25 15:58:05 +08:00
const beginDay = new Date().getTime()
for (let i = 0; i < 10; i++) {
2019-04-14 16:20:04 +08:00
sourceData.push({
2019-02-25 15:58:05 +08:00
x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'),
y: Math.round(Math.random() * 10)
})
}
export default {
2019-04-14 16:20:04 +08:00
name: 'MiniArea',
props: {
dataSource: {
2019-02-25 15:58:05 +08:00
type: Array,
2019-04-14 16:20:04 +08:00
default: () => []
},
// x 轴别名
x: {
type: String,
default: 'x'
},
// y 轴别名
y: {
type: String,
default: 'y'
2019-02-25 15:58:05 +08:00
}
},
2019-04-14 16:20:04 +08:00
data() {
2019-02-25 15:58:05 +08:00
return {
2019-04-14 16:20:04 +08:00
data: [],
2019-02-25 15:58:05 +08:00
height: 100
}
2019-04-14 16:20:04 +08:00
},
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
}
2019-02-25 15:58:05 +08:00
}
}
</script>
<style lang="scss" scoped>
@import "chart";
</style>