桑基图优化

This commit is contained in:
1340691923@qq.com 2022-02-07 15:25:54 +08:00
parent a121765433
commit 719ff5de46
2 changed files with 208 additions and 164 deletions

View File

@ -1,18 +1,25 @@
## 铸龙-用户行为分析系统
技术栈主要用: Vue + golang
欢迎大家提出自己的issue。
铸龙-用户事件分析系统
----------- -----------
> 铸龙-用户事件分析系统 是一款用来进行分析用户行为事件的BI软件功能如下 > 铸龙-用户行为分析系统 是一款用于分析用户行为事件的BI软件功能如下
* 事件分析 * 事件分析
* 漏斗分析 * 漏斗分析
* 留存分析 * 留存分析
* 智能路径分析 * 智能路径分析
* 报表,面板管理 * 报表,面板管理
> 技术栈主要用
* 前端vue+elementui+antdv
* 后端go
> 所需中间件
* mysql
* redis
* kafka
* clickhouse
欢迎大家提出自己的issue。
## 相关 ## 相关
[下载地址]( https://gitee.com/cynthia520/xwl_bi/releases/v1.0.0 ) [下载地址]( https://gitee.com/cynthia520/xwl_bi/releases/v1.0.0 )
[文档地址]( https://www.yuque.com/jianghurenchenggolang/oehqme/hen7qy ) [文档地址]( https://www.yuque.com/jianghurenchenggolang/oehqme/hen7qy )

View File

@ -1,5 +1,5 @@
<template> <template>
<div :id="className" :class="className" :style="{height:height,width:width}" /> <div :class="className" :id="className" :style="{height:height,width:width}"/>
</template> </template>
<script> <script>
@ -7,6 +7,7 @@
//require('echarts/theme/macarons') // echarts theme //require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize' import resize from './mixins/resize'
import {setNotopt} from './mixins/utils' import {setNotopt} from './mixins/utils'
export default { export default {
mixins: [resize], mixins: [resize],
props: { props: {
@ -36,9 +37,7 @@ export default {
chart: null chart: null
} }
}, },
watch: { watch: {},
},
mounted() { mounted() {
this.initChart() this.initChart()
}, },
@ -54,18 +53,51 @@ export default {
this.chart = echarts.init(document.getElementById(this.className)) this.chart = echarts.init(document.getElementById(this.className))
this.setOptions() this.setOptions()
}, },
getColor1() {//
var re = "#";
var col = this.color();
re += col + "FF";
return re
},
getColor2() {//
var re = "#FF";
var col = this.color();
re += col;
return re
},
color() {
var re = "";
for (var loopNum = 0; loopNum < 2; loopNum++) {
var temp = Math.floor(256 * Math.random());
if (temp < 130 && loopNum == 0) {
temp = 130;
}
if (temp > 200 && loopNum == 1) {
temp = 200;
}
temp = temp.toString(16);//16
if (temp.length !== 2) {
temp = "0" + temp
}
re += temp//
}
return re;
},
setOptions() { setOptions() {
if (this.chartData.length == 0) { if (this.chartData.length == 0) {
setNotopt(this.chart) setNotopt(this.chart)
return return
} }
const eventArr = [] let eventArr = []
const targetArr = [] let targetArr = []
const eventSet = new Map() let eventSet = new Map()
for (const k in this.chartData) { for (let k in this.chartData) {
const traceCharts = this.chartData[k] let traceCharts = this.chartData[k]
eventSet.set(traceCharts['event'][0], 1) eventSet.set(traceCharts['event'][0], 1)
eventSet.set(traceCharts['event'][1], 1) eventSet.set(traceCharts['event'][1], 1)
@ -73,104 +105,109 @@ export default {
targetArr.push({ targetArr.push({
source: traceCharts['event'][0], source: traceCharts['event'][0],
target: traceCharts['event'][1], target: traceCharts['event'][1],
value: traceCharts['sum_user_count'] value: traceCharts['sum_user_count'],
}) })
} }
eventSet.forEach((v, k, tmp) => { eventSet.forEach((v, k, tmp) => {
const obj = { let color = ""
name: k var random = Math.random();
if(random <0.618){//分配红色和蓝色出现的比例
color = this.getColor1()
}else{
color = this.getColor2()
}
let obj = {
name: k,
itemStyle: {
color: color
}
} }
eventArr.push(obj) eventArr.push(obj)
}) })
const option = { let levelsArr = []
toolbox: {
feature: { for (let i in eventArr) {
saveAsImage: {} levelsArr.push({
} depth: i,
itemStyle: {
color: eventArr[i].itemStyle.color
}, },
lineStyle: {
color: 'source',
opacity: 0.4
}
})
}
let option = {
tooltip: { tooltip: {
trigger: 'item', trigger: 'item',
triggerOn: 'mousemove' triggerOn: 'mousemove'
}, },
series: [ backgroundColor: '#FFFFFF',
{ series: {
type: 'sankey', type: 'sankey',
emphasis: { layout: 'none',
focus: 'adjacency' top: 50,
left: '3%',
right: '12%',
nodeGap: 14,
layoutIterations: 0, // 线0
data: eventArr, //
links: targetArr, // 线
focusNodeAdjacency: 'allEdges', // 线allEdges线线
levels: [{
depth: 0,
itemStyle: {
color: '#F27E7E'
}, },
nodeAlign: 'left',
data: eventArr,
links: targetArr,
lineStyle: { lineStyle: {
color: 'source', color: 'source',
curveness: 0.5 opacity: 0.4
}
}
]
}
try {
this.chart.setOption(
option
)
} catch (e) {
this.setOptions2()
} }
}, },
setOptions2() {
const eventArr = []
const targetArr = []
const eventSet = new Map()
for (const k in this.chartData) {
const traceCharts = this.chartData[k]
eventSet.set(traceCharts['event'][0] + ' ', 1)
eventSet.set(traceCharts['event'][1] + ' ', 1)
targetArr.push({
source: traceCharts['event'][0] + ' ',
target: traceCharts['event'][1] + ' ',
value: traceCharts['sum_user_count']
})
}
eventSet.forEach((v, k, tmp) => {
const obj = {
name: k
}
eventArr.push(obj)
})
const option = {
toolbox: {
feature: {
saveAsImage: {}
}
},
tooltip: {
trigger: 'item',
triggerOn: 'mousemove'
},
series: [
{ {
type: 'sankey', depth: 1,
emphasis: {
focus: 'adjacency'
},
nodeAlign: 'left',
data: eventArr,
links: targetArr,
lineStyle: { lineStyle: {
color: 'source', color: 'source',
curveness: 0.5 opacity: 0.4
}
},
{
depth: 2,
lineStyle: {
color: 'source',
opacity: 0.4
}
},
{
depth: 3,
label: {
fontSize: 12
}
}
],
label: {
fontSize: 14,
color: '#666'
},
itemStyle: {
normal: {
borderWidth: 0
}
} }
} }
]
} }
this.chart.setOption( this.chart.setOption(
option option
) )
} }
} }
} }
</script> </script>