效果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e547226984ec5927639d2a5cf9631249.png)
源码
data() {
return {
chartTitleFontSize: 0,
chartInstance: null,
allData: null,
}
},
computed: {
titleStyle() {
return {
fontSize: `${this.chartTitleFontSize * 1.5}px`
}
}
},
mounted() {
this.initChart()
this.getData()
window.addEventListener('resize', this.screenAdapter)
this.screenAdapter()
},
destroyed() {
window.removeEventListener('resize', this.screenAdapter)
},
methods:{
initChart() {
this.chartInstance = this.$echarts.init(this.$refs.chart_ref)
const initOption = {
color: ['#00fff5'],
grid: {
top: "25%",
left: "5%",
bottom: "5%",
right: "5%",
containLabel: true
},
animation: false,
xAxis: [
{
type: 'category',
axisLabel: {
interval: 0,
color: '#739DC9',
margin: 15,
formatter: function (params) {
var newParamsName = ''
var paramsNameNumber = params.length
var provideNumber = 4
var rowNumber = Math.ceil(paramsNameNumber / provideNumber)
if (paramsNameNumber > provideNumber) {
for (var p = 0; p < rowNumber; p++) {
var tempStr = ''
var start = p * provideNumber
var end = start + provideNumber
if (p == rowNumber - 1) {
tempStr = params.substring(start, paramsNameNumber)
} else {
tempStr = params.substring(start, end) + '\n'
}
newParamsName += tempStr
}
} else {
newParamsName = params
}
return newParamsName
},
},
axisLine: {
show: false,
},
axisTick: {
show: false,
},
boundaryGap: '6%',
splitLine: {
show: false,
width: 0.08,
lineStyle: {
type: 'solid',
color: '#03202E',
},
},
},
],
yAxis: [
{
show: false
},
],
series: [
{
name: "数据上椭圆",
type: 'pictorialBar',
colorBy: 'data',
symbolOffset: [0, -6],
symbolPosition: 'end',
z: 12,
label: {
show: true,
position: "top",
fontSize: 14,
color: 'inherit',
formatter: function (params, index) {
return params.value
}
},
},
{
name: '下椭圆',
type: 'pictorialBar',
colorBy: 'data',
symbolOffset: [0, 7],
z: 12,
},
{
name: '下实现线环',
type: 'pictorialBar',
colorBy: 'data',
symbolOffset: [0, 9],
z: 12,
itemStyle: {
color: 'transparent',
borderColor: '#1eadcd',
borderType: 'solid',
borderWidth: 12
},
},
{
name: '下虚线环',
type: 'pictorialBar',
colorBy: 'data',
symbolOffset: [0, 12],
z: 12,
itemStyle: {
color: 'transparent',
borderColor: '#1eadcd',
borderType: 'dashed',
borderWidth: 12
},
},
{
type: 'bar',
barGap: '10%',
barCateGoryGap: '10%',
itemStyle: {
color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 0.7, [{
offset: 0,
color: "rgba(22, 168, 194,.7)"
},
{
offset: 1,
color: "rgba(22, 168, 194,.3)"
}
])
}
},
]
}
this.chartInstance.setOption(initOption)
},
getData() {
const data = [{
name: '侨领数量',
value: 460
}, {
name: '专业人员数量',
value: 2824
}]
this.allData = data
this.allData.sort((a, b) => {
return b.value - a.value
})
this.updateChart()
},
updateChart() {
const categoryName = this.allData.map((item) => { return item.name })
const categoryValue = this.allData.map(item => { return item.value })
const dataOption = {
xAxis: [{
data: categoryName
}],
series: [
{
type: 'pictorialBar',
data: categoryValue,
},
{
type: 'pictorialBar',
data: categoryValue,
},
{
type: 'pictorialBar',
data: categoryValue,
},
{
type: 'pictorialBar',
data: categoryValue,
},
{
type: 'bar',
data: categoryValue,
}
]
}
this.chartInstance.setOption(dataOption)
},
screenAdapter() {
this.chartTitleFontSize = this.$refs.chart_title_ref.offsetWidth / 100 * 3.6
const adapterOption = {
xAxis: [{
axisLabel: {
fontSize: this.chartTitleFontSize,
}
}],
series: [
{
type: 'pictorialBar',
symbolSize: [this.chartTitleFontSize * 2, 10],
},
{
type: 'pictorialBar',
symbolSize: [this.chartTitleFontSize * 2, 10],
},
{
type: 'pictorialBar',
symbolSize: [this.chartTitleFontSize * 3, 12],
},
{
type: 'pictorialBar',
symbolSize: [this.chartTitleFontSize * 5, 16],
},
{
type: 'bar',
barWidth: this.chartTitleFontSize * 2
}
]
}
this.chartInstance.setOption(adapterOption)
this.chartInstance.resize()
}
}