PathFlowChart.vue
2.73 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<template>
<div class="path-flow-container">
<div ref="chart" class="chart-container"></div>
</div>
</template>
<script>
import * as echarts from 'echarts'
import { nodes, links } from './chartData'
export default {
name: 'PathFlowChart',
data() {
return {
chart: null
}
},
mounted() {
this.$nextTick(() => {
this.initChart()
window.addEventListener('resize', this.resizeChart)
})
},
beforeDestroy() {
window.removeEventListener('resize', this.resizeChart)
if (this.chart) {
this.chart.dispose()
}
},
methods: {
resizeChart() {
if (this.chart) {
this.chart.resize()
}
},
initChart() {
const chartDom = this.$refs.chart
this.chart = echarts.init(chartDom)
const option = {
title: {
text: '用户行为路径分析',
left: 'center',
top: 10
},
tooltip: {
trigger: 'item',
triggerOn: 'mousemove'
},
series: [
{
type: 'sankey',
data: nodes,
links: links,
left: '3%',
right: '3%',
top: '5%',
bottom: '5%',
nodeWidth: 100,
nodeGap: 15,
layoutIterations: 0,
emphasis: {
focus: 'adjacency'
},
itemStyle: {
borderWidth: 1,
borderColor: '#fff'
},
lineStyle: {
color: 'gradient',
curveness: 0.5,
opacity: 0.3
},
label: {
position: 'inside',
formatter: function(params) {
// Hide label for loss nodes if any (though we set show:false in data)
if (params.data.isLoss) return ''
const name = params.name.replace(/\s\(\d+\)$/, '')
return `{name|${name}}\n{value|${params.data.value}}`
},
rich: {
name: {
fontSize: 12,
fontWeight: 'bold',
color: '#fff',
lineHeight: 18
},
value: {
fontSize: 12,
color: '#fff',
lineHeight: 18
}
}
}
}
]
}
this.chart.setOption(option)
}
}
}
</script>
<style scoped>
.path-flow-container {
width: 100%;
background: #fff;
margin-top: 20px;
padding: 20px;
border-radius: 4px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.chart-container {
width: 100%;
height: 800px;
}
</style>