湖里大屏:更改 jChart/bar/JBarChart.vue 组件封装

This commit is contained in:
Jack 2022-08-04 16:12:33 +08:00
parent dc5a3f9584
commit d950a89b2f
2 changed files with 59 additions and 91 deletions

View File

@ -26,7 +26,10 @@ export default {
default: () => [] default: () => []
}, },
yData: { yData: {
required: true, type: Array,
default: () => []
},
series: {
type: Array, type: Array,
default: () => [] default: () => []
} }
@ -40,7 +43,15 @@ export default {
}, },
methods: { methods: {
createChart() { createChart() {
const { title, grid, color, xData, yData } = this const { title, grid, color, xData, yData, series } = this
const configSeries = (series => {
if (series.length) {
return series.map(item => ({ data: item.data, type: 'bar', barWidth: 15 }))
} else {
return [{ data: yData, type: 'bar', barWidth: 15 }]
}
})(series)
const option = { const option = {
title: { title: {
text: title.text, text: title.text,
@ -104,13 +115,7 @@ export default {
show: false show: false
} }
}, },
series: [ series: configSeries
{
data: yData,
type: 'bar',
barWidth: 15
}
]
} }
this.jBarChart.setOption(option) this.jBarChart.setOption(option)
} }

View File

@ -1,112 +1,75 @@
<template> <template>
<!-- 年龄结构 --> <Card :title="title">
<div class="containerBox">
<div class="titleTxt">{{ title }}</div>
<div class="topTit"> <div class="topTit">
<div class="blue"></div><span>在场</span> <div class="blue"></div>
<div class="purple"></div><span>在职</span> <span>在场</span>
<div class="purple"></div>
<span>在职</span>
<div class="topright"> <div class="topright">
<p>在职平均年龄 <a>42</a></p> <p>在职平均年龄 <a>42</a></p>
<p>在场平均年龄 <a>42</a></p> <p>在场平均年龄 <a>42</a></p>
</div> </div>
</div> </div>
<div class="mychart"> <div class="mychart">
<JBarChart :xData="xData" :yData="yData" :color="color" :grid="grid" /> <JBarChart :xData="xData" :series="series" :color="color" :grid="grid" />
</div> </div>
</div> </Card>
</template> </template>
<script> <script>
import JBarChart from "../jChart/bar/JBarChart.vue"; import Card from '../components/Card.vue'
import JBarChart from '../jChart/bar/JBarChart.vue'
export default { export default {
components: { JBarChart }, components: { Card, JBarChart },
props: { props: {
title: { title: {
type: String, type: String,
default: "default title" default: 'default title'
} }
}, },
data() { data() {
return { return {
xData: ["18岁及下", "18-45岁", "45-59岁", "60岁以上"], xData: ['18岁及下', '18-45岁', '45-59岁', '60岁以上'],
yData: [ series: [{ data: [22, 33, 22, 56] }, { data: [32, 22, 32, 15] }],
{ color: ['#5be2f6', '#5281f7'],
value: 170, grid: ['10%', '5%', '15%', '5%']
itemStyle: { }
color: "#a9adb6"
}
},
{
value: 320,
itemStyle: {
color: "#557dee"
}
},
{
value: 270,
itemStyle: {
color: "#43d7b5"
}
},
{
value: 310,
itemStyle: {
color: "#ff6c7f"
}
}
],
color: ["#5be2f6", "#5281f7"],
grid: ["10%", "5%", "15%", "5%"]
};
} }
}; }
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.containerBox { .topTit {
width: 100%; font-size: 12px;
height: 100%; color: #5d6674;
border: 1px solid #0081c3; .blue,
.purple {
.titleTxt {
font-size: 18px;
color: #6ee4f0;
margin-top: 5px;
margin-left: 5px;
}
.topTit{
font-size: 12px;
color: #5d6674;
.blue , .purple{
display: inline-block;
width: 15px;
height: 5px;
border-radius: 10px;
margin-left: 30px;
margin-right: 5px;
background-color: #5be2f6;
}
.purple{
background-color: #5181f7;
}
// span{
// margin-right: 30px;
// height: 15px;
// line-height: 15px;
// }
}
.topright{
display: inline-block; display: inline-block;
p { width: 15px;
margin-left: 110px; height: 5px;
} border-radius: 10px;
margin-left: 30px;
margin-right: 5px;
background-color: #5be2f6;
} }
.mychart { .purple {
width: 100%; background-color: #5181f7;
height: 90%; }
// span{
// margin-right: 30px;
// height: 15px;
// line-height: 15px;
// }
}
.topright {
display: inline-block;
p {
margin-left: 110px;
} }
} }
.mychart {
width: 100%;
height: calc(100% - 28px);
}
</style> </style>