湖里大屏:完成 jChart/bar/JBarChart.vue 组件封装

This commit is contained in:
Jack 2022-08-03 11:14:46 +08:00
parent 15d8437e66
commit 800bc64341
2 changed files with 82 additions and 53 deletions

View File

@ -6,76 +6,108 @@
import echarts from 'echarts4' import echarts from 'echarts4'
export default { export default {
props: { props: {
data: { title: {
type: Object,
default: () => ({
text: ''
})
},
grid: {
type: Array, type: Array,
default: () => [{ value: 1, name: '' }] default: () => ['15%', '2%', '2%', '2%']
}, },
color: { color: {
type: Array, type: Array,
default: () => ['#5181F6', '#61D2B9', '#F67F51', '#7851F6'] default: () => ['#5EC2D0', '#61D2B9', '#F67F51', '#7851F6']
}, },
title: { xData: {
type: String, required: true,
default: ''
},
subTitle: {
type: String,
default: ''
},
radius: {
type: Array, type: Array,
default: () => ['65%', '80%'] default: () => []
},
yData: {
required: true,
type: Array,
default: () => []
} }
}, },
mounted() { mounted() {
this.jBarChart = echarts.init(this.$refs.jBarChart) this.jBarChart = echarts.init(this.$refs.jBarChart)
this.createRingChart() this.createChart()
}, },
data() { data() {
return { jBarChart: null } return { jBarChart: null }
}, },
methods: { methods: {
createRingChart() { createChart() {
const { title, grid, color, xData, yData } = this
const option = { const option = {
color: this.color,
title: { title: {
show: true, text: title.text,
text: this.title, right: 20,
x: '48%',
y: '36%',
z: 5,
textAlign: 'center',
textStyle: { textStyle: {
color: 'rgba(255, 255, 255, 1)', fontSize: '14px',
fontSize: 20 color: '#5EC2D0',
}, fontWeight: 'normal'
subtext: this.subTitle,
subtextStyle: {
color: 'rgba(255, 255, 255, 0.8)',
fontSize: 13
} }
}, },
grid: { grid: {
right: 0 top: grid[0],
right: grid[1],
bottom: grid[2],
left: grid[3],
containLabel: true
}, },
legend: { color,
show: false xAxis: {
type: 'category',
data: xData,
axisLine: {
show: true,
lineStyle: {
type: [5, 10]
}
},
axisLabel: {
show: true,
textStyle: {
color: '#fff'
}
},
axisTick: {
show: false
}
},
yAxis: {
type: 'value',
splitLine: {
show: true,
lineStyle: {
type: [5, 10],
color: '#323D50'
}
},
axisLine: {
show: true,
lineStyle: {
type: [5, 10]
}
},
axisLabel: {
show: true,
textStyle: {
color: '#fff'
}
},
axisTick: {
show: false
}
}, },
series: [ series: [
{ {
name: '', data: yData,
type: 'pie', type: 'bar',
radius: this.radius, barWidth: 15
avoidLabelOverlap: false,
hoverAnimation: false,
label: {
show: false,
position: 'center'
},
labelLine: {
show: false
},
data: this.data
} }
] ]
} }

View File

@ -3,13 +3,7 @@
<div class="frequentProblems"> <div class="frequentProblems">
<div class="title">{{ title }}</div> <div class="title">{{ title }}</div>
<div class="content"> <div class="content">
<JBarChart <JBarChart :xData="xData" :yData="yData" :title="{ text: '频发问题类别排名前十' }" />
title="3412"
subTitle="问题总数"
:color="['#557DEE', '#43D7B5']"
:data="[{ value: 2314 }, { value: 987 }]"
:radius="['55%', '80%']"
/>
</div> </div>
</div> </div>
</template> </template>
@ -25,7 +19,10 @@ export default {
} }
}, },
data() { data() {
return {} return {
xData: ['地理老师', '地理老师', '地理老师', '地理老师', '地理老师', '地理老师', '地理老师', '地理老师', '地理老师', '地理老师'],
yData: [100, 235, 232, 532, 112, 532, 449, 269, 998, 33]
}
} }
} }
</script> </script>