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

This commit is contained in:
Jack 2022-08-03 14:12:43 +08:00
parent f684ab3409
commit b3d91d2fdb
2 changed files with 62 additions and 58 deletions

View File

@ -6,21 +6,11 @@
import echarts from 'echarts4' import echarts from 'echarts4'
export default { export default {
props: { props: {
title: {
type: Object,
default: () => ({
text: ''
})
},
grid: { grid: {
type: Array, type: Array,
default: () => ['15%', '2%', '2%', '2%'] default: () => ['10', '8%', '10', '10']
}, },
color: { seriesData: {
type: Array,
default: () => ['#5EC2D0', '#61D2B9', '#F67F51', '#7851F6']
},
xData: {
required: true, required: true,
type: Array, type: Array,
default: () => [] default: () => []
@ -40,17 +30,10 @@ export default {
}, },
methods: { methods: {
createChart() { createChart() {
const { title, grid, color, xData, yData } = this const { grid, seriesData, yData } = this
const max = Math.max(...seriesData)
const maxData = seriesData.map(item => max)
const option = { const option = {
title: {
text: title.text,
right: 20,
textStyle: {
fontSize: '14px',
color: '#5EC2D0',
fontWeight: 'normal'
}
},
grid: { grid: {
top: grid[0], top: grid[0],
right: grid[1], right: grid[1],
@ -58,56 +41,77 @@ export default {
left: grid[3], left: grid[3],
containLabel: true containLabel: true
}, },
color,
xAxis: { xAxis: {
type: 'category', type: 'value',
data: xData,
axisLine: {
show: true,
lineStyle: {
type: [5, 10]
}
},
axisLabel: { axisLabel: {
show: true, formatter: () => ''
textStyle: { },
color: '#fff' splitLine: {
} show: false
},
axisLine: {
show: false
}, },
axisTick: { axisTick: {
show: false show: false
} }
}, },
yAxis: { yAxis: {
type: 'value', type: 'category',
splitLine: {
show: true,
lineStyle: {
type: [5, 10],
color: '#323D50'
}
},
axisLine: { axisLine: {
show: true, show: false
lineStyle: {
type: [5, 10]
}
},
axisLabel: {
show: true,
textStyle: {
color: '#fff'
}
}, },
axisTick: { axisTick: {
show: false show: false
},
data: yData,
axisLabel: {
textStyle: {
fontSize: 12,
color: 'rgba(225, 225, 225, .8)'
}
} }
}, },
series: [ series: [
{ {
data: yData,
type: 'bar', type: 'bar',
barWidth: 15 itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
{ offset: 0, color: '#4A90E2' },
{ offset: 1, color: '#4ADEE2' }
]),
barBorderRadius: 3
},
label: {
show: true,
position: 'right',
color: 'white',
textStyle: {
fontSize: 15
}
},
data: seriesData,
barWidth: 13
},
{
type: 'bar',
itemStyle: {
color: 'rgba(255, 255, 255, 0.1)',
barBorderRadius: 3
},
// label: {
// show: true,
// position: 'right',
// color: 'white',
// textStyle: {
// fontSize: 15
// }
// },
barGap: '-100%',
barCategoryGap: '40%',
data: maxData,
barWidth: 13,
animation: false
} }
] ]
} }

View File

@ -2,7 +2,7 @@
<div class="question-type"> <div class="question-type">
<div class="title">{{ title }}</div> <div class="title">{{ title }}</div>
<div class="content"> <div class="content">
<JProgressChart :xData="xData" :yData="yData" :title="{ text: '频发问题类别排名前十' }" /> <JProgressChart :seriesData="seriesData" :yData="yData" />
</div> </div>
</div> </div>
</template> </template>
@ -19,8 +19,8 @@ export default {
}, },
data() { data() {
return { return {
xData: ['地理老师', '地理老师', '地理老师', '地理老师', '地理老师', '地理老师', '地理老师', '地理老师', '地理老师', '地理老师'], yData: ['地理老师', '地理老师', '地理老师', '地理老师', '地理老师', '地理老师', '地理老师', '地理老师', '地理老师', '地理老师'],
yData: [100, 235, 232, 532, 112, 532, 449, 269, 998, 33] seriesData: [100, 235, 232, 532, 112, 532, 449, 269, 998, 33]
} }
} }
} }