Files
base/jero-web/src/components/chart/LineChartMultid.vue
T

95 lines
2.5 KiB
Java

<template>
<div :style="{ padding: '0 0 32px 32px' }">
<h4 :style="{ marginBottom: '20px' }">{{ title }}</h4>
<v-chart :force-fit="true" :height="height" :data="data" :scale="scale" :onClick="handleClick">
<v-tooltip/>
<v-axis/>
<v-legend/>
<v-line position="type*y" color="x"/>
<v-point position="type*y" color="x" :size="4" :v-style="style" :shape="'circle'"/>
</v-chart>
</div>
</template>
<script>
import { DataSet } from '@antv/data-set'
import { ChartEventMixins } from './mixins/ChartMixins'
export default {
name: 'LineChartMultid',
mixins: [ChartEventMixins],
props: {
title: {
type: String,
default: ''
},
dataSource: {
type: Array,
default: () => [
{ type: 'Jan', jeroOne: 7.0, jeroTwo: 3.9 },
{ type: 'Feb', jeroOne: 6.9, jeroTwo: 4.2 },
{ type: 'Mar', jeroOne: 9.5, jeroTwo: 5.7 },
{ type: 'Apr', jeroOne: 14.5, jeroTwo: 8.5 },
{ type: 'May', jeroOne: 18.4, jeroTwo: 11.9 },
{ type: 'Jun', jeroOne: 21.5, jeroTwo: 15.2 },
{ type: 'Jul', jeroOne: 25.2, jeroTwo: 17.0 },
{ type: 'Aug', jeroOne: 26.5, jeroTwo: 16.6 },
{ type: 'Sep', jeroOne: 23.3, jeroTwo: 14.2 },
{ type: 'Oct', jeroOne: 18.3, jeroTwo: 10.3 },
{ type: 'Nov', jeroOne: 13.9, jeroTwo: 6.6 },
{ type: 'Dec', jeroOne: 9.6, jeroTwo: 4.8 }
]
},
fields: {
type: Array,
default: () => ['jeroOne', 'jeroTwo']
},
// 别名,需要的格式:[{field:'name',alias:'姓名'}, {field:'sex',alias:'性别'}]
aliases:{
type: Array,
default: () => []
},
height: {
type: Number,
default: 254
}
},
data() {
return {
scale: [{
type: 'cat',
dataKey: 'x',
min: 0,
max: 1
}],
style: { stroke: '#fff', lineWidth: 1 }
}
},
computed: {
data() {
const dv = new DataSet.View().source(this.dataSource)
dv.transform({
type: 'fold',
fields: this.fields,
key: 'x',
value: 'y'
})
let rows = dv.rows
// 替换别名
rows.forEach(row => {
for (let item of this.aliases) {
if (item.field === row.x) {
row.x = item.alias
break
}
}
})
return rows
}
}
}
</script>
<style scoped>
</style>