Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
gh
/
data-view
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 1cdd9b6b
authored
Jun 28, 2022
by
王志慧
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
pie图
1 parent
adcf4e60
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
168 additions
and
64 deletions
src/components/PieChart.vue
src/components/RanKing.vue
src/mixins/clientMixin.js
src/views/customer/age.vue
src/views/customer/buyCar.vue
src/views/customer/sex.vue
src/components/PieChart.vue
View file @
1cdd9b6
<
template
>
<
template
>
<div
class=
"pie-box"
>
<div
class=
"pie-box"
>
<div
:id=
"id"
:style=
"
{ width: width, height: height }" class="pie-chart">
</div>
<div
:id=
"id"
:style=
"
{ width: width, height: height }" class="pie-chart">
</div>
<div
class=
"center-content"
>
<div
:class=
"[id, 'center-content-num']"
></div>
<div
class=
"center-content-desc"
>
{{
numDesc
}}
</div>
</div>
</div>
</div>
</
template
>
</
template
>
...
@@ -16,7 +20,7 @@ export default {
...
@@ -16,7 +20,7 @@ export default {
},
},
keys
:
{
keys
:
{
type
:
Array
,
type
:
Array
,
default
:
()
=>
[
'name'
,
'
number
'
]
default
:
()
=>
[
'name'
,
'
value
'
]
},
},
height
:
{
height
:
{
type
:
String
,
type
:
String
,
...
@@ -28,13 +32,7 @@ export default {
...
@@ -28,13 +32,7 @@ export default {
},
},
list
:
{
list
:
{
type
:
Array
,
type
:
Array
,
default
:
()
=>
[
default
:
()
=>
[]
{
number
:
1048
,
name
:
'Search Engine'
},
{
number
:
735
,
name
:
'Direct'
},
{
number
:
580
,
name
:
'Email'
},
{
number
:
484
,
name
:
'Union Ads'
},
{
number
:
300
,
name
:
'Video Ads'
}
]
},
},
radius
:
{
radius
:
{
type
:
Array
,
type
:
Array
,
...
@@ -53,20 +51,23 @@ export default {
...
@@ -53,20 +51,23 @@ export default {
mTime
:
''
,
mTime
:
''
,
viewData
:
[],
viewData
:
[],
text
:
''
,
text
:
''
,
subtext
:
''
subtext
:
''
,
currentIndex
:
-
1
,
mainValue
:
0
,
numDesc
:
''
}
}
},
},
watch
:
{
created
()
{
list
:
{
handler
(
newVal
)
{
this
.
initData
()
this
.
initData
()
this
.
draw
()
}
}
},
},
mounted
()
{
mounted
()
{
let
id
=
this
.
id
this
.
initData
()
this
.
echartsPie
=
echarts
.
init
(
document
.
getElementById
(
id
))
window
.
addEventListener
(
'resize'
,
()
=>
{
this
.
echartsPie
.
resize
()
})
this
.
draw
()
this
.
draw
()
},
},
...
@@ -82,6 +83,10 @@ export default {
...
@@ -82,6 +83,10 @@ export default {
})
})
},
},
draw
()
{
draw
()
{
this
.
echartsPie
=
echarts
.
init
(
document
.
getElementById
(
this
.
id
))
window
.
addEventListener
(
'resize'
,
()
=>
{
this
.
echartsPie
.
resize
()
})
// 指定图表的配置项和数据
// 指定图表的配置项和数据
this
.
option
=
{
this
.
option
=
{
// tooltip: {
// tooltip: {
...
@@ -147,10 +152,22 @@ export default {
...
@@ -147,10 +152,22 @@ export default {
]
]
}
}
this
.
echartsPie
.
setOption
(
this
.
option
)
this
.
echartsPie
.
setOption
(
this
.
option
)
this
.
pieActive
(
)
this
.
mTime
=
setInterval
(
this
.
pieActive
,
3000
)
// 鼠标划出
// 鼠标划出
this
.
echartsPie
.
on
(
'mouseout'
,
()
=>
{
this
.
echartsPie
.
on
(
'mouseout'
,
()
=>
{
this
.
pieActive
()
if
(
this
.
mTime
)
clearInterval
(
this
.
mTime
)
this
.
mTime
=
setInterval
(
this
.
pieActive
,
3000
)
})
this
.
echartsPie
.
on
(
'mouseover'
,
data
=>
{
this
.
mainValue
=
data
.
data
.
value
this
.
numDesc
=
data
.
data
.
name
this
.
setAnamiteText
()
// 停止定时器,清除之前的高亮
clearInterval
(
this
.
mTime
)
console
.
log
(
'mouseover'
)
this
.
currentIndex
=
data
.
dataIndex
this
.
highlightPie
()
this
.
emitEvent
(
data
.
data
)
})
})
},
},
// 事件触发
// 事件触发
...
@@ -160,44 +177,35 @@ export default {
...
@@ -160,44 +177,35 @@ export default {
this
.
echartsPie
.
setOption
(
this
.
option
)
this
.
echartsPie
.
setOption
(
this
.
option
)
this
.
$emit
(
'pieAction'
,
data
)
this
.
$emit
(
'pieAction'
,
data
)
},
},
//高亮
highlightPie
()
{
pieActive
()
{
// 取消所有高亮并高亮当前图形
let
index
=
-
1
//高亮所在下标
// 遍历饼图数据,取消所有图形的高亮效果
let
dataLength
=
this
.
viewData
.
length
// 当前饼图有多少个扇形
for
(
var
idx
in
this
.
option
.
series
[
0
].
data
)
// 用定时器控制饼图高亮
this
.
mTime
=
setInterval
(()
=>
{
// 清除之前的高亮
this
.
echartsPie
.
dispatchAction
({
this
.
echartsPie
.
dispatchAction
({
type
:
'downplay'
,
type
:
'downplay'
,
seriesIndex
:
0
,
seriesIndex
:
0
,
dataIndex
:
i
nde
x
dataIndex
:
i
d
x
})
})
index
=
(
index
+
1
)
%
dataLength
// 高亮当前图形
// 当前下标高亮
this
.
echartsPie
.
dispatchAction
({
this
.
echartsPie
.
dispatchAction
({
type
:
'highlight'
,
type
:
'highlight'
,
seriesIndex
:
0
,
seriesIndex
:
0
,
dataIndex
:
index
dataIndex
:
this
.
currentIndex
})
if
(
index
>
dataLength
)
{
index
=
0
}
this
.
emitEvent
(
this
.
viewData
[
index
])
},
2000
)
// 鼠标划入
this
.
echartsPie
.
on
(
'mouseover'
,
data
=>
{
// 停止定时器,清除之前的高亮
clearInterval
(
this
.
mTime
)
this
.
echartsPie
.
dispatchAction
({
type
:
'downplay'
,
seriesIndex
:
0
,
dataIndex
:
index
})
console
.
log
(
'mouseover'
)
console
.
log
(
data
)
this
.
emitEvent
(
data
.
data
)
})
})
//高亮项this.currentIndex
this
.
mainValue
=
this
.
option
.
series
[
0
].
data
[
this
.
currentIndex
].
value
this
.
numDesc
=
this
.
option
.
series
[
0
].
data
[
this
.
currentIndex
].
name
this
.
setAnamiteText
()
},
setAnamiteText
()
{
document
.
querySelector
(
`.
${
this
.
id
}
`
).
style
=
`--step:
${
this
.
mainValue
}
`
},
//高亮
pieActive
()
{
const
dataLen
=
this
.
option
.
series
[
0
].
data
.
length
this
.
currentIndex
=
(
this
.
currentIndex
+
1
)
%
dataLen
this
.
highlightPie
()
this
.
emitEvent
(
this
.
viewData
[
this
.
currentIndex
])
}
}
}
}
}
}
...
@@ -206,7 +214,53 @@ export default {
...
@@ -206,7 +214,53 @@ export default {
<
style
lang=
"scss"
scoped
>
<
style
lang=
"scss"
scoped
>
.pie-box
{
.pie-box
{
background
:
#262525
;
background
:
#262525
;
position
:
relative
;
.center-content
{
position
:
absolute
;
top
:
50%
;
left
:
50%
;
transform
:
translate
(
-50%
,
-50%
);
text-align
:
center
;
&-num
{
font-size
:
0.24vw
;
color
:
#fff
;
--step
:
0
;
counter-reset
:
count
var
(
--step
);
z-index
:
var
(
--step
);
transition
:
--step
1s
;
&::before
{
content
:
counter
(
count
);
}
}
&
-desc
{
font-size
:
0.2vw
;
color
:
#606266
;
white-space
:
nowrap
;
animation
:
rotateIn
2s
infinite
;
}
}
.pie-chart
{
.pie-chart
{
}
}
}
}
@property
--step
{
syntax
:
'<integer>'
;
inherits
:
false
;
initial-value
:
15
;
}
@keyframes
rotateIn
{
from
{
transform
:
rotateY
(
0turn
);
}
to
{
transform
:
rotateY
(
-1turn
);
}
}
//
@keyframes
rotateIn
{
//
from
{
//
transform
:
rotateZ
(
0deg
);
//
}
//
to
{
//
transform
:
rotateZ
(
3600deg
);
//
}
//
}
</
style
>
</
style
>
src/components/RanKing.vue
View file @
1cdd9b6
...
@@ -2,9 +2,9 @@
...
@@ -2,9 +2,9 @@
<div
class=
"ranking-container"
>
<div
class=
"ranking-container"
>
<div
class=
"title"
>
品牌排名
</div>
<div
class=
"title"
>
品牌排名
</div>
<div
class=
"ranking"
>
<div
class=
"ranking"
>
<div
class=
"brand flex"
v-for=
"(item, index) in
5
"
:key=
"index"
>
<div
class=
"brand flex"
v-for=
"(item, index) in
brandList
"
:key=
"index"
>
<span
class=
"brand-num"
>
{{
index
+
1
}}
</span>
<span
class=
"brand-num"
>
{{
index
+
1
}}
</span>
<marquee
class=
"marquee"
:direction=
"directionTimer"
:delay=
"delayTimer"
:text=
"
text
"
/>
<marquee
class=
"marquee"
:direction=
"directionTimer"
:delay=
"delayTimer"
:text=
"
item
"
/>
</div>
</div>
</div>
</div>
</div>
</div>
...
@@ -12,11 +12,24 @@
...
@@ -12,11 +12,24 @@
<
script
>
<
script
>
export
default
{
export
default
{
name
:
'RanKing'
,
name
:
'RanKing'
,
props
:
{
list
:
{
type
:
Array
,
default
:
()
=>
[]
}
},
watch
:
{
list
:
{
handler
(
newVal
)
{
this
.
brandList
=
newVal
}
}
},
data
()
{
data
()
{
return
{
return
{
delayTimer
:
3000
,
delayTimer
:
3000
,
directionTimer
:
3000
,
directionTimer
:
3000
,
text
:
'丰田丰田丰田丰田丰田'
brandList
:
this
.
list
}
}
}
}
}
}
...
...
src/mixins/clientMixin.js
View file @
1cdd9b6
export
default
{
export
default
{
data
()
{
data
()
{
return
{
return
{
now
:
new
Date
().
format
(
'yyyy-MM-dd'
)
now
:
new
Date
().
format
(
'yyyy-MM-dd'
),
clientData
:
[],
distributionRank
:
''
}
}
},
},
created
()
{
created
()
{
...
@@ -11,14 +13,25 @@ export default {
...
@@ -11,14 +13,25 @@ export default {
getClientData
()
{
getClientData
()
{
const
params
=
{
const
params
=
{
req
:
{
req
:
{
corporateGroupName
:
'广汇'
,
corporateGroupName
:
'集团1'
,
queryItem
:
'age'
,
queryItem
:
this
.
type
,
queryTime
:
this
.
now
,
// queryTime: this.now,
queryTime
:
'2022-06-23'
,
queryType
:
0
queryType
:
0
}
}
}
}
this
.
api
.
customer
.
overalldistribution
(
params
).
then
(
res
=>
{
this
.
api
.
customer
.
overalldistribution
(
params
).
then
(
res
=>
{
console
.
log
(
res
)
let
distribution
=
JSON
.
parse
(
res
.
data
.
dataList
[
0
].
distribution
)
const
keys
=
Object
.
keys
(
distribution
)
keys
.
forEach
((
item
,
index
)
=>
{
this
.
clientData
.
push
({
name
:
item
,
value
:
distribution
[
item
]
})
})
console
.
log
(
res
.
data
.
dataList
[
0
].
distributionRank
)
this
.
distributionRank
=
JSON
.
parse
(
res
.
data
.
dataList
[
0
].
distributionRank
)
// console.log(this.distributionRank,'this.distributionRank')
})
})
}
}
}
}
...
...
src/views/customer/age.vue
View file @
1cdd9b6
...
@@ -12,8 +12,8 @@
...
@@ -12,8 +12,8 @@
<span>
客户年龄分布
</span>
<span>
客户年龄分布
</span>
</div>
</div>
<div
class=
"container flex"
>
<div
class=
"container flex"
>
<pie-chart
:id=
"chart.id"
></pie-chart>
<pie-chart
:id=
"chart.id"
:list=
"clientData"
@
pieAction=
"pieAction"
></pie-chart>
<ran-king></ran-king>
<ran-king
:list=
"brandList"
></ran-king>
</div>
</div>
</div>
</div>
</
template
>
</
template
>
...
@@ -25,10 +25,17 @@ export default {
...
@@ -25,10 +25,17 @@ export default {
mixins
:
[
clientMixin
],
mixins
:
[
clientMixin
],
data
()
{
data
()
{
return
{
return
{
type
:
'age'
,
brandList
:[],
chart
:
{
chart
:
{
id
:
'age-pie'
id
:
'age-pie'
}
}
}
}
},
methods
:{
pieAction
(
data
){
this
.
brandList
=
Object
.
keys
(
this
.
distributionRank
[
data
.
name
])
}
}
}
}
}
</
script
>
</
script
>
src/views/customer/buyCar.vue
View file @
1cdd9b6
...
@@ -12,21 +12,30 @@
...
@@ -12,21 +12,30 @@
<span>
客户购车年限
</span>
<span>
客户购车年限
</span>
</div>
</div>
<div
class=
"container flex"
>
<div
class=
"container flex"
>
<pie-chart
:id=
"chart.id"
></pie-chart>
<pie-chart
:id=
"chart.id"
:list=
"clientData"
@
pieAction=
"pieAction"
></pie-chart>
<ran-king></ran-king>
<ran-king
:list=
"brandList"
></ran-king>
</div>
</div>
</div>
</div>
</
template
>
</
template
>
<
script
>
<
script
>
import
{
clientMixin
}
from
'../../mixins/index'
export
default
{
export
default
{
name
:
'BuyCar'
,
name
:
'BuyCar'
,
data
(){
mixins
:
[
clientMixin
],
data
()
{
return
{
return
{
type
:
'buycarRange'
,
brandList
:
[],
chart
:
{
chart
:
{
id
:
'car-pie'
id
:
'car-pie'
}
}
}
}
},
methods
:
{
pieAction
(
data
)
{
this
.
brandList
=
Object
.
keys
(
this
.
distributionRank
[
data
.
name
])
}
}
}
}
}
</
script
>
</
script
>
src/views/customer/sex.vue
View file @
1cdd9b6
...
@@ -12,20 +12,28 @@
...
@@ -12,20 +12,28 @@
<span>
客户性别
</span>
<span>
客户性别
</span>
</div>
</div>
<div
class=
"container flex"
>
<div
class=
"container flex"
>
<pie-chart
:id=
"chart.id"
></pie-chart>
<pie-chart
:id=
"chart.id"
:list=
"clientData"
@
pieAction=
"pieAction"
></pie-chart>
<ran-king></ran-king>
<ran-king
:list=
"brandList"
></ran-king>
</div>
</div>
</div>
</div>
</
template
>
</
template
>
<
script
>
<
script
>
import
{
clientMixin
}
from
'../../mixins/index'
export
default
{
export
default
{
name
:
'Sex'
,
name
:
'Sex'
,
mixins
:
[
clientMixin
],
data
()
{
data
()
{
return
{
return
{
type
:
'gender'
,
chart
:
{
chart
:
{
id
:
'sex-pie'
id
:
'sex-pie'
}
}
}
}
},
methods
:{
pieAction
(
data
){
this
.
brandList
=
Object
.
keys
(
this
.
distributionRank
[
data
.
name
])
}
}
}
}
}
</
script
>
</
script
>
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