Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wisdom-property
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
郭铭瑶
wisdom-property
Commits
069d5032
Commit
069d5032
authored
Mar 17, 2020
by
郭铭瑶
🤘
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图表组件加同心圆功能
parent
306eb16a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
115 additions
and
17 deletions
+115
-17
monitor-card.vue
...components/MonitorComponents/MonitorCard/monitor-card.vue
+4
-1
monitor-chart.vue
...mponents/MonitorComponents/MonitorChart/monitor-chart.vue
+111
-16
No files found.
src/components/MonitorComponents/MonitorCard/monitor-card.vue
View file @
069d5032
<
template
>
<m-animate
:enter=
"enter"
:leave=
"leave"
>
<div
class=
"monitor-card"
>
<component
:is=
"card"
v-bind=
"$attrs"
>
<component
:is=
"card"
v-bind=
"$attrs"
:title=
"title"
>
<slot/>
</component>
</div>
...
...
@@ -12,6 +12,9 @@
export
default
{
name
:
'MonitorCard'
,
props
:
{
title
:
{
type
:
String
,
},
mode
:
{
type
:
[
String
,
Number
],
default
:
'1'
,
...
...
src/components/MonitorComponents/MonitorChart/monitor-chart.vue
View file @
069d5032
...
...
@@ -88,6 +88,7 @@ export default {
/** 设置坐标轴 */
setAxis
(
options
)
{
const
{
xAxis
,
yAxis
,
shape
}
=
this
.
config
if
(
shape
[
0
].
type
===
'pie'
||
shape
[
0
].
type
===
'donut'
)
return
const
config
=
{
data
:
this
.
data
.
map
(
item
=>
item
[(
yAxis
&&
yAxis
.
key
)
||
xAxis
.
key
]),
boundaryGap
:
!
shape
.
every
(
item
=>
item
.
type
===
'line'
)
...
...
@@ -130,16 +131,16 @@ export default {
/** 设置图例说明 */
setLegend
(
options
)
{
const
{
legend
}
=
this
.
config
if
(
legend
.
hide
)
{
if
(
legend
&&
legend
.
hide
)
{
options
.
grid
.
top
=
'5%'
return
}
options
.
legend
=
Object
.
assign
({},
this
.
defaultOptions
.
legend
,
this
.
options
.
legend
)
if
(
legend
.
orient
)
{
if
(
legend
&&
legend
.
orient
)
{
options
.
legend
.
orient
=
legend
.
orient
}
options
.
legend
.
data
=
this
.
dataSource
.
map
(
item
=>
item
.
name
)
switch
(
legend
.
align
)
{
switch
(
legend
&&
legend
.
align
)
{
case
'left'
:
options
.
legend
.
left
=
'5%'
break
...
...
@@ -156,19 +157,11 @@ export default {
const
{
shape
}
=
this
.
config
// 如果为饼图则数据需是[{name: 'name', value: 1}]格式,且不需要坐标轴
if
(
shape
[
0
].
type
===
'pie'
)
{
options
.
color
=
this
.
colors
options
.
series
=
[{
label
:
{
normal
:
{
show
:
false
,
},
},
...
shape
[
0
],
}]
options
.
series
[
0
].
data
=
options
.
legend
.
data
=
this
.
data
options
.
tooltip
.
trigger
=
'item'
this
.
$delete
(
options
,
'xAxis'
)
this
.
$delete
(
options
,
'yAxis'
)
this
.
setPie
(
options
)
return
}
if
(
shape
[
0
].
type
===
'donut'
)
{
this
.
setDonut
(
options
)
return
}
...
...
@@ -198,6 +191,90 @@ export default {
return
result
})
},
// 绘制饼图
setPie
(
options
)
{
const
{
shape
}
=
this
.
config
options
.
color
=
this
.
colors
options
.
series
=
[{
label
:
{
normal
:
{
show
:
false
,
},
},
...
shape
[
0
],
}]
if
(
options
.
legend
&&
options
.
legend
.
data
)
{
options
.
series
[
0
].
data
=
options
.
legend
.
data
=
this
.
data
}
else
{
options
.
series
[
0
].
data
=
this
.
data
}
options
.
tooltip
.
trigger
=
'item'
this
.
$delete
(
options
,
'xAxis'
)
this
.
$delete
(
options
,
'yAxis'
)
},
// 绘制同心圆图
setDonut
(
options
)
{
const
{
shape
}
=
this
.
config
options
.
color
=
this
.
colors
options
.
series
=
this
.
getDonutConfig
(
shape
)
},
getDonutConfig
(
args
)
{
const
len
=
args
.
length
if
(
len
<=
0
)
return
const
total
=
this
.
data
.
reduce
((
acc
,
cur
)
=>
{
// 计算数据的value总和
return
acc
+
cur
.
value
},
0
)
return
args
.
map
((
e
,
i
)
=>
{
const
rate
=
Math
.
round
((
len
-
i
)
*
this
.
fontSize
)
let
borderColor
=
this
.
colors
[
i
]
if
(
Array
.
isArray
(
borderColor
))
{
borderColor
=
{
type
:
'linear'
,
x
:
0
,
y
:
0
,
x2
:
0
,
y2
:
1
,
colorStops
:
[{
offset
:
0
,
color
:
borderColor
[
0
]
// 0% 处的颜色
},
{
offset
:
1
,
color
:
borderColor
[
1
]
// 100% 处的颜色
}],
global
:
false
,
// 缺省为 false
}
}
return
{
type
:
'pie'
,
name
:
e
.
name
,
clockWise
:
false
,
//顺时加载
hoverAnimation
:
false
,
//鼠标移入变大
radius
:
[
rate
,
rate
+
1
],
itemStyle
:
{
normal
:
{
label
:
{
show
:
false
,
},
labelLine
:
{
show
:
false
,
},
borderWidth
:
this
.
borderWidth
,
borderColor
:
borderColor
,
}
},
data
:
[
this
.
data
[
i
],
{
value
:
Math
.
round
(
total
-
this
.
data
[
i
].
value
),
name
:
''
,
itemStyle
:
this
.
blackStyle
,
}
]
}
})
},
},
computed
:
{
colors
()
{
...
...
@@ -290,6 +367,24 @@ export default {
fontSize
()
{
return
Math
.
floor
(
screen
.
height
*
1.48
/
100
)
},
borderWidth
()
{
return
this
.
fontSize
*
0.6
},
blackStyle
()
{
return
{
normal
:
{
label
:
{
show
:
false
,
},
labelLine
:
{
show
:
false
},
color
:
'transparent'
,
borderColor
:
'rgba(0,0,0,0.1)'
,
borderWidth
:
this
.
borderWidth
,
},
}
},
},
watch
:
{
data
(
cur
,
past
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment