Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas
/
scrm-micro-custom
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit c89e93cb
authored
Dec 06, 2023
by
前端
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
等待联调
1 parent
3917b2fc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
95 additions
and
48 deletions
src/views/userPortrait/components/BarChart.vue
src/views/userPortrait/components/LineChart.vue
src/views/userPortrait/components/PieChart.vue
src/views/userPortrait/index.vue
src/views/userPortrait/components/BarChart.vue
View file @
c89e93c
<
template
>
<div
class=
"bar-chart"
>
<p
class=
"line-color-title"
>
{{
title
}}
</p>
<div
ref=
"barChart"
style=
"width: 100%; height: 30vh;"
></div>
<div
v-if=
"data"
ref=
"barChart"
style=
"width: 100%; height: 30vh;"
></div>
</div>
</
template
>
...
...
@@ -27,6 +27,10 @@ export default {
[
'#6E77FF'
,
'#A1D9FF'
],
// 渐变色1
[
'#90D55C'
,
'#FDDB93'
],
// 渐变色2
]
},
rotate
:{
type
:
Number
,
default
:
45
}
},
watch
:
{
...
...
@@ -49,14 +53,15 @@ export default {
axisLine
:
{
show
:
false
},
axisLabel
:
{
interval
:
0
,
rotate
:
45
rotate
:
this
.
rotate
}
},
yAxis
:
{
type
:
'value'
,
axisTick
:
{
show
:
false
},
axisLine
:
{
show
:
false
},
splitLine
:
{
show
:
false
},
minInterval
:
1
,
// 确保Y轴刻度间隔最小为1,避免数据过小时出现小数点
// axisTick: { show: false },
// axisLine: { show: false },
// splitLine: { show: false },
// axisLabel: { show: false }
},
series
:
[{
...
...
@@ -69,13 +74,15 @@ export default {
},
itemStyle
:
{
color
:
(
params
)
=>
{
const
dataIndex
=
params
.
dataIndex
const
gradientIndex
=
Math
.
floor
(
dataIndex
%
2
)
const
dataIndex
=
params
.
dataIndex
;
const
gradientIndex
=
dataIndex
%
this
.
colors
.
length
;
// 循环使用渐变色
const
colorPair
=
this
.
colors
[
gradientIndex
];
return
{
type
:
'linear'
,
colorStops
:
[
{
offset
:
0
,
color
:
this
.
colors
[
gradientIndex
]
[
0
]
},
{
offset
:
1
,
color
:
this
.
colors
[
gradientIndex
]
[
1
]
},
{
offset
:
0
,
color
:
colorPair
[
0
]
},
{
offset
:
1
,
color
:
colorPair
[
1
]
},
],
globalCoord
:
false
,
x
:
0
,
// 渐变的起始点横坐标
...
...
@@ -84,14 +91,9 @@ export default {
y2
:
1
,
// 渐变的结束点纵坐标(设置为1表示从上到下
};
},
barBorderRadius
:
5
barBorderRadius
:
3
}
// itemStyle: {
// color: (params) => {
// return this.colors[params.dataIndex % this.colors.length];
// },
// barBorderRadius: 5
// }
}]
};
...
...
@@ -102,9 +104,9 @@ export default {
</
script
>
<
style
lang=
"scss"
>
#chart
{
width
:
100%
;
height
:
400px
;
}
//
#chart
{
//
width
:
100%
;
//
height
:
400px
;
//
}
</
style
>
src/views/userPortrait/components/LineChart.vue
View file @
c89e93c
<
template
>
<div
class=
"line-chart"
>
<p
class=
"line-color-title"
>
{{
title
}}
</p>
<div
ref=
"lineChart"
style=
"width: 100%; height:30vh;"
></div>
<div
v-if=
"data"
ref=
"lineChart"
style=
"width: 100%; height:30vh;"
></div>
</div>
</
template
>
...
...
@@ -46,11 +46,12 @@ export default {
xAxis
:
{
type
:
'category'
,
boundaryGap
:
false
,
axisTick
:
{
show
:
false
},
//
axisTick: { show: false },
data
:
this
.
data
.
map
(
item
=>
item
.
name
),
},
yAxis
:
{
type
:
'value'
,
minInterval
:
1
,
// 确保Y轴刻度间隔最小为1,避免数据过小时出现小数点
},
series
:
[
{
...
...
src/views/userPortrait/components/PieChart.vue
View file @
c89e93c
<
template
>
<div>
<p
class=
"line-color-title"
>
{{
title
}}
</p>
<div
ref=
"pieChart"
style=
"margin-top:10px;width: 100%; height: 20
vh;"
></div>
<div
v-if=
"data"
ref=
"pieChart"
style=
"margin-top:10px;width: 100%; height:22
vh;"
></div>
</div>
</
template
>
...
...
@@ -25,12 +25,32 @@ export default {
default
:
()
=>
[
'#50CEFB'
,
'#5850FF'
,
'#FBBE50'
,
'#90D55C'
,
'#FDDB93'
,
'#A1EDFF'
,
'#6EA3FF'
,
'#FF5A92'
,
'#BCCAFF'
,
'#9F6EFF'
],
},
},
data
()
{
return
{
dynamicRichStyles
:
{},
};
},
mounted
()
{
this
.
initChart
(
this
.
$refs
.
pieChart
);
this
.
drawChart
();
},
methods
:
{
generateRichStyles
()
{
this
.
colors
.
forEach
((
color
,
index
)
=>
{
this
.
dynamicRichStyles
[
'style'
+
index
]
=
{
color
:
color
,
fontWeight
:
'bold'
,
fontSize
:
'17px'
};
});
},
createFormatter
(
params
)
{
const
styleKey
=
'style'
+
(
params
.
dataIndex
%
this
.
colors
.
length
);
return
`{
${
styleKey
}
|
${
params
.
value
}
%}\n\n{b|
${
params
.
name
}
}`
;
},
drawChart
()
{
this
.
generateRichStyles
();
// 生成动态样式
const
chart
=
echarts
.
init
(
this
.
$refs
.
pieChart
);
const
option
=
{
...
...
@@ -45,25 +65,12 @@ export default {
type
:
'pie'
,
radius
:
[
'40%'
,
'60%'
],
avoidLabelOverlap
:
false
,
minAngle
:
50
,
// 设置最小角度为50度,针对传入的数据为0
label
:
{
show
:
true
,
position
:
'outside'
,
formatter
:
function
(
params
)
{
return
'{a|'
+
params
.
value
+
'%'
+
'}'
+
'\n'
+
'\n'
+
' {b|'
+
params
.
name
+
'}'
},
rich
:
{
a
:
{
color
:
'#50CEFB'
,
fontWeight
:
'bold'
,
fontSize
:
'18px'
},
b
:
{
color
:
'#333'
,
fontSize
:
'14px'
,
}
}
formatter
:
this
.
createFormatter
,
// 引用 formatter 函数
rich
:
this
.
dynamicRichStyles
,
// 使用动态生成的样式
},
labelLine
:
{
show
:
true
...
...
src/views/userPortrait/index.vue
View file @
c89e93c
<
template
>
<!-- 该页面图表显示的颜色均可通过传入color参数修改-->
<!-- 该页面图表显示的颜色均可通过传入color参数修改-->
<div
class=
"dashboard"
>
<!-- 用户信息部分 -->
<div
class=
"user-section"
>
...
...
@@ -13,13 +13,20 @@
<!-- 图表部分 -->
<div
class=
"charts-section"
>
<PieChart
:title=
"'客户来源'"
v-if=
"sourceDistribution"
:data=
"sourceDistribution"
/>
<PieChart
:title=
"'租住比'"
v-if=
"lodgeDistribution"
:data=
"lodgeDistribution"
/>
<PieChart
:title=
"'消费能力'"
v-if=
"consumeDistribution"
:data=
"consumeDistribution"
/>
<PieChart
:title=
"'车辆类型'"
v-if=
"vehicleDistribution"
:data=
"vehicleDistribution"
/>
<PieChart
:title=
"'客户来源'"
:data=
"sourceDistribution"
/>
<PieChart
:title=
"'租住比'"
:data=
"lodgeDistribution"
/>
<PieChart
:title=
"'消费能力'"
:data=
"consumeDistribution"
/>
<PieChart
:title=
"'车辆类型'"
:data=
"vehicleDistribution"
/>
<LineChart
:title=
"'浏览时段偏好'"
v-if=
"browseDistribution"
:data=
"browseDistribution"
/>
<BarChart
:title=
"'甄选商品偏好(top10)'"
v-if=
"productDistribution"
:data=
"productDistribution"
></BarChart>
<BarChart
:title=
"'甄选商品偏好(top10)'"
:data=
"productDistribution"
></BarChart>
<BarChart
:title=
"'攻略偏好(top10)'"
:data=
"productDistribution"
></BarChart>
<BarChart
:title=
"'权益购买偏好(top10)'"
:data=
"productDistribution"
></BarChart>
<LineChart
:title=
"'浏览时段偏好'"
:data=
"browseDistribution"
/>
<PieChart
:title=
"'客户购买转化阶段'"
:data=
"vehicleDistribution"
/>
<BarChart
:title=
"'客户全生命周期价值(LTV)'"
:data=
"productDistribution"
:colors=
"[['#6E77FF', '#A1D9FF']]"
:rotate=
"0"
></BarChart>
</div>
</div>
...
...
@@ -75,13 +82,42 @@ export default {
methods
:
{
async
getUserPortraitData
()
{
// 44209572
const
merchantId
=
44209572
// this.$globalState.session.merchantId
await
this
.
$apis
.
userPortrait
.
getPortraitData
({
merchantId
:
this
.
$globalState
.
session
.
merchantId
}).
then
(
res
=>
{
await
this
.
$apis
.
userPortrait
.
getPortraitData
({
merchantId
}).
then
(
res
=>
{
for
(
const
key
in
res
)
{
if
(
this
.
hasOwnProperty
(
key
))
{
this
[
key
]
=
res
[
key
]
}
}
this
.
productDistribution
=
[{
name
:
"配件用品"
,
value
:
0
},
{
name
:
"商品3"
,
value
:
0
},
{
name
:
"化妆用品"
,
value
:
1
},
{
name
:
"划船20232"
,
value
:
1
},
{
name
:
"商品1"
,
value
:
0
},
{
name
:
"休闲零食"
,
value
:
1
},
{
name
:
"划船5"
,
value
:
0
},
{
name
:
"划船"
,
value
:
1
},
{
name
:
"日常用品"
,
value
:
3
}]
})
},
findSexCount
(
sex
)
{
...
...
@@ -113,9 +149,10 @@ export default {
width
:
69vw
;
grid-template-columns
:
repeat
(
2
,
1
fr
);
gap
:
20px
;
background-color
:
#fff
;
padding
:
10px
;
overflow-y
:
auto
;
//
添加这一行来实现滚动
max-height
:
89.5vh
;
//
可以设置一个最大高度,超过这个高度将显示滚动条
}
}
</
style
>
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment