zxl
2026-03-23 b924e4fe906c3e1b4e804ed9d073e09db76fc710
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<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 './chart-mixins'
 
export default {
  name: 'LineChartMulti',
 
  mixins: [ChartEventMixins],
 
  props: {
    title: {
      type: String,
      default: ''
    },
    dataSource: {
      type: Array,
      default: () => []
    },
    fields: {
      type: Array,
      default: () => ['jeecg', 'jeebt']
    },
    // 别名,需要的格式:[{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>