Commit f4801d83 by 匡雅琴

饼图

1 parent d7e52feb
<template>
<div class="legend">
<div class="legend-item flex" v-for="(item, index) in dataList" :key="index">
<div class="icon" :style="{ background: colors[index] }"></div>
<div class="item-content">{{ item.name }}</div>
</div>
</div>
</template>
<script>
export default {
name: 'Legend',
data() {
return {
dataList: this.list
}
},
props: {
list: {
type: Array,
default: () => []
},
colors: {
type: Array,
default: () => ['#FF6E76', '#7CFFB2', ' #FDF006', '#4FA0FF', '#EB6001', '#BF98FF', '#BF98FF', '#58D9F9']
}
},
watch: {
list(val) {
this.dataList = val
}
},
mounted() {},
methods: {}
}
</script>
<style lang="scss" scoped>
.legend {
display: flex;
align-items: center;
flex-wrap: wrap;
width: 7.7vw;
height: 8.54vh;
margin-left: 0.42vw;
.legend-item {
width: 3.68vw;
height: 2.44vh;
background: #0d133b;
align-items: center;
font-size: 7px;
color: #fff;
box-sizing: border-box;
margin: 2px 2px 2px 0;
white-space: nowrap;
.item-content {
width: 2.5vw;
overflow: hidden;
}
.icon {
width: 5px;
height: 5px;
background: #bf98ff;
border-radius: 50%;
margin: 4px;
}
}
}
</style>
<template>
<div class="pie-box">
<div :id="id" :style="{ height: height }" class="pie-chart"></div>
<!-- <div class="center-content" :style="{ fontSize: size }">
<div :class="[id, 'center-content-num', 'center-content-num-color']"></div>
</div> -->
<!-- <div class="content-desc">
<div class="content-desc-icon" :style="{ background: descColor }"></div>
{{ numDesc }}
</div> -->
</div>
</template>
<script>
import * as echarts from 'echarts'
export default {
name: 'PieChart',
props: {
id: {
type: String,
default: ''
},
keys: {
type: Array,
default: () => ['name', 'value']
},
height: {
type: String,
default: '8.54vh'
},
list: {
type: Array,
default: () => []
},
radius: {
type: Array,
default: () => ['60%', '89%']
},
colors: {
type: Array,
default: () => ['#FF6E76', '#7CFFB2', ' #FDF006']
},
size: {
type: String,
default: '0.6vw'
}
},
data() {
return {
option: '',
echartsPie: '',
mTime: '',
viewData: [],
text: '',
subtext: '',
currentIndex: -1,
mainValue: 0,
numDesc: '',
descColor: ''
}
},
watch: {
list: {
handler(newVal) {
if (newVal.length > 0) {
this.initData()
this.$nextTick(() => {
this.draw()
})
}
},
immediate: true
}
},
mounted() {},
methods: {
// 初始化数据
initData() {
const { list, keys } = this
this.viewData = []
list.forEach(item => {
this.viewData.push({
name: item[keys[0]],
value: item[keys[1]]
})
})
console.log(this.viewData)
},
draw() {
if (this.mTime) clearInterval(this.mTime)
this.echartsPie = echarts.init(document.getElementById(this.id))
window.addEventListener('resize', () => {
this.echartsPie.resize()
})
// 指定图表的配置项和数据
this.option = {
// tooltip: {
// trigger: 'item'
// },
color: this.colors,
series: [
{
name: '客户年龄分布',
type: 'pie',
radius: this.radius,
center: ['50%', '50%'],
avoidLabelOverlap: false,
label: {
normal: {
show: false,
position: 'center'
},
show: false,
position: 'center'
},
emphasis: {
label: {
show: true,
fontSize: this.size,
fontWeight: 'bold',
color: '#fff',
formatter: '{d}%'
}
},
labelLine: {
show: false
},
data: this.viewData,
minAngle: 30
}
]
}
this.echartsPie.clear()
this.mainValue = 0
this.numDesc = ''
console.log(11111);
this.echartsPie.setOption(this.option)
this.pieActive()
this.mTime = setInterval(this.pieActive, 15000)
// 鼠标划出
this.echartsPie.on('mouseout', () => {
if (this.mTime) clearInterval(this.mTime)
this.mTime = setInterval(this.pieActive, 15000)
})
this.echartsPie.on('mouseover', data => {
this.mainValue = data.data.value
this.numDesc = data.data.name
this.descColor = data.color
// 停止定时器,清除之前的高亮
clearInterval(this.mTime)
this.currentIndex = data.dataIndex
this.highlightPie()
this.emitEvent(data.data)
})
},
// 事件触发
emitEvent(data) {
this.echartsPie.setOption(this.option)
this.$emit('pieAction', data)
},
highlightPie() {
// 取消所有高亮并高亮当前图形
// 遍历饼图数据,取消所有图形的高亮效果
for (var idx in this.option.series[0].data) {
this.echartsPie.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: idx
})
}
// 高亮当前图形
this.echartsPie.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: this.currentIndex
})
this.descColor = this.option.color[this.currentIndex]
},
// 高亮
pieActive() {
const dataLen = this.option.series[0].data.length
this.currentIndex = (this.currentIndex + 1) % dataLen
this.highlightPie()
this.emitEvent(this.viewData[this.currentIndex])
}
}
}
</script>
<style lang="scss" scoped>
.pie-box {
// background: #262525;
position: relative;
flex: 1;
.center-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
max-width: 40%;
&-num-color {
color: #fff;
}
&-num {
// overflow: hidden;
// text-overflow: ellipsis;
// white-space: nowrap;
// font-size: 0.6vw;
--step: 0;
counter-reset: count var(--step);
z-index: var(--step);
transition: --step 0.5s;
&::before {
content: counter(count);
}
}
&-desc {
font-size: 0.5vw;
color: #606266;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
animation: rotateIn 3s infinite;
}
}
.content-desc {
display: flex;
align-items: center;
font-size: 8px;
color: #c8c8c8;
text-align: center;
font-weight: 400;
position: absolute;
top: 91%;
left: 50%;
transform: translateX(-50%);
text-align: center;
height: 14px !important;
white-space: nowrap;
&-icon {
width: 8px;
height: 4px;
border-radius: 2px;
margin-right: 4px;
}
}
}
@property --step {
syntax: '<integer>';
inherits: false;
initial-value: 15;
}
@keyframes rotateIn {
from {
transform: rotateY(0turn);
}
to {
transform: rotateY(-1turn);
}
}
</style>
...@@ -85,7 +85,6 @@ export default { ...@@ -85,7 +85,6 @@ export default {
width: 0.69vw; width: 0.69vw;
height: 0.67vh; height: 0.67vh;
} }
} }
} }
</style> </style>
...@@ -22,10 +22,10 @@ ...@@ -22,10 +22,10 @@
</div> </div>
</div> </div>
<!-- 门店排行 --> <!-- 门店排行 -->
<div v-for="(item, index) in merchantsList" :key="index" class="merchant-box"> <div class="merchant-box">
<div class="merchant-box-item"> <div v-for="(item, index) in merchantsList" :key="index" class="merchant-box-item">
<div class="merchant-box-item-left"> <div class="merchant-box-item-left">
<div class="circle" :style="{ 'background-image': index < 3 ? perchaseColorList[index] : '' }">{{ index }}</div> <div class="circle" :style="{ 'background-image': index < 3 ? perchaseColorList[index] : '' }">{{ index + 1 }}</div>
<div class="text">{{ item.name }}</div> <div class="text">{{ item.name }}</div>
</div> </div>
<div class="merchant-box-item-right">{{ item.value }}</div> <div class="merchant-box-item-right">{{ item.value }}</div>
...@@ -36,23 +36,35 @@ ...@@ -36,23 +36,35 @@
<!-- 右侧第一个盒子 --> <!-- 右侧第一个盒子 -->
<div class="right-box2"> <div class="right-box2">
<box-title title="商城采购进度分析"></box-title> <box-title title="商城采购进度分析"></box-title>
<RightViewContent :chart="progressChart" :listData="progressData"></RightViewContent>
<!-- 内容 -->
</div> </div>
<!-- 右侧第一个盒子 --> <!-- 右侧第一个盒子 -->
<div class="right-box3"> <div class="right-box3">
<box-title title="商城采购额商品占比"></box-title> <box-title title="商城采购额商品占比"></box-title>
<!-- 内容 -->
</div> </div>
</div> </div>
</template> </template>
<script type="text/ecmascript-6"> <script type="text/ecmascript-6">
import RightViewContent from './RightViewContent.vue'
export default { export default {
name: 'ContentRight', name: 'ContentRight',
components: {
RightViewContent
},
data() { data() {
return { return {
// 采购额排名下拉框显示
isShow: false, isShow: false,
// 采购额排名下拉框数据
purchaseList: ['商城采购', '商城采购商城采购商城采购商城采购商城采购城采购商', '自采', '商城采购商城采购商城采购商城'], purchaseList: ['商城采购', '商城采购商城采购商城采购商城采购商城采购城采购商', '自采', '商城采购商城采购商城采购商城'],
// 采购额排名当前选中值
purchase: '商城采购', purchase: '商城采购',
// 采购额排名前三图标颜色
perchaseColorList: ['linear-gradient(180deg, #FFDA0B 0%, #FFBC24 100%)', 'linear-gradient(180deg, #EBE5D6 0%, #BDB4A6 100%)', 'linear-gradient(180deg, #EEC08E 0%, #B86E3A 100%)'], perchaseColorList: ['linear-gradient(180deg, #FFDA0B 0%, #FFBC24 100%)', 'linear-gradient(180deg, #EBE5D6 0%, #BDB4A6 100%)', 'linear-gradient(180deg, #EEC08E 0%, #B86E3A 100%)'],
// 采购额排名门店数据
merchantsList: [ merchantsList: [
{ {
name: '公转一号店', name: '公转一号店',
...@@ -74,6 +86,29 @@ export default { ...@@ -74,6 +86,29 @@ export default {
name: '公转一号店', name: '公转一号店',
value: '345489' value: '345489'
} }
],
// 采购进度饼图结构
progressChart: {
id: 'progress',
keys: ['isDelivery', 'per']
},
// 采购进度数据
progressData: [
{
isDelivery: '已发货',
per: '36%',
price: 4568
},
{
isDelivery: '未发货',
per: '20%',
price: 4568
},
{
isDelivery: '已发货',
per: '36%',
price: 4568
}
] ]
} }
}, },
...@@ -163,16 +198,33 @@ export default { ...@@ -163,16 +198,33 @@ export default {
} }
} }
.merchant-box { .merchant-box {
margin-top: 2.06vh;
&-item { &-item {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
padding-bottom: 1vh;
&-left { &-left {
display: flex; display: flex;
.circle { .circle {
width: 1.39vw; width: 20px;
height: 1.39vh; height: 20px;
background: #1E3372; border-radius: 20px;
font-size: 14px;
color: #ffffff;
text-align: center;
background: #1e3372;
}
.text {
font-weight: 400;
font-size: 14px;
color: #ffffff;
margin-left: 1.11vw;
cursor: default;
}
.text:hover {
padding-bottom: 1px;
border-bottom: 1px solid #fff;
} }
} }
&-right { &-right {
......
<template>
<div>
<!-- <pie-chart :id="chart.id" :list="listData" :keys="chart.keys"></pie-chart> -->
<div id="pie1" style="width: 200px;height:200px;"></div>
</div>
</template>
<script>
// import * as echarts from 'echarts'
export default {
name: 'RightViewContent',
props: {
chart: {
type: Object,
default: () => {}
},
listData: {
type: Array,
default: () => []
}
},
data() {
return {}
},
mounted() {},
methods: {}
}
</script>
<style lang="scss" scoped></style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!