zhaojs
2023-09-15 39e2103e28830337c3be4dbd3dc7ad0a829ee78b
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
<template>
  <div :style="{ padding: '0 0 32px 32px' }">
    <h4 :style="{ marginBottom: '20px' }">{{ title }}</h4>
    <v-chart :force-fit="true" height="354" :data="data" :scale="scale">
      <v-tooltip />
      <v-axis />
      <v-legend />
      <v-line :position="position" color="city" />
      <v-point :position="position" color="city" :size="4" :v-style="style" :shape="'circle'" />
    </v-chart>
  </div>
</template>
 
<script>
const DataSet = require('@antv/data-set')
export default {
  name: 'MultiLine',
  props: {
    title: {
      type: String,
      default: ''
    },
    fields: {
      type: Array,
      default: () => {
        return []
      }
    },
    sourceData: {
      type: Array,
      default: () => {
        return []
      }
    },
    position: {
      type: String,
      default: () => {
        return 'x*y'
      }
    },
    scale: {
      type: Array,
      default: () => {
        return [{ dataKey: 'month', min: 0, max: 1 }]
      }
    }
  },
  data () {
    return {
      data: [],
      style: { stroke: '#fff', lineWidth: 1 }
    }
  },
  watch:
  {
    sourceData: function (val) {
      if (val.length > 0) {
        this.initMultiLine(val)
      }
    }
  },
  mounted () {
    if (this.sourceData.length > 0) {
        this.initMultiLine(this.sourceData)
      }
  },
  methods:
  {
    initMultiLine (data) {
      const dv = new DataSet.View().source(data)
      dv.transform({
        type: 'fold',
        fields: this.fields,
        key: 'city',
        value: 'y'
      })
      this.data = dv.rows
    }
  }
}
</script>