問題:v-charts拓展配置extend中的yAxis屁柏,xAxis,series...不能配置以數(shù)組的形式配置有送。請參考球員身價配置
<template>
<section class="box-wrap">
<div class="box" ref="boxRef">
<p class="title">進球時間分布</p>
<ve-histogram :width="`${width}px`" height="110px" :data="analyseGoal.chartData" :settings="chartSettings" :extend="chartExtend"></ve-histogram>
</div>
<p class="model-title">球員身價TOP3</p>
<div class="box" ref="boxRef">
<ve-histogram :width="`${width}px`" height="150px" :data="analysePlayer.chartData" :settings="chartSettings1" :extend="chartExtend1" :mark-line="markLine"></ve-histogram>
</div>
</section>
</template>
<style>
.box-wrap{
padding: 30px;
background: #fff;
.box{
width: 100%;
min-height: 274px;
overflow: hidden;
background: #fff;
box-shadow: 0 2px 10px 0 rgba(0,0,0,0.06);
border-radius: 10px;
padding: 20px 0;
/* margin: 30px 0; */
.title{
font-family: PingFangSC-Semibold;
font-size: 24px;
color: #606060;
margin: 0 20px;
}
}
.model-title{
font-family: PingFangSC-Semibold;
font-size: 32px;
color: #303030;
line-height: 28px;
padding: 30px 0;
}
}
</style>
<script>
export default {
data () {
const _this = this;
this.chartSettings = {
legendLimit: 0,
};
this.chartExtend = {
color: ['#5E6E8C'],
legend: {
show: false
},
tooltip: {
show: false
},
yAxis: {
axisLabel: {show: false},
splitLine: {show: false},
axisLine: {show: false},
axisTick: {show: false},
splitArea: {show: false},
type : 'value',
},
xAxis:{
axisLabel: {
interval: 0,
color: 'rgba(48,48,48, .5)',
fontSize: 10,
fontFamily: 'PingFangSC-Regular',
},
axisLine: {
show: true,
lineStyle: {
fontSize: 14,
color: '#DADADA', // 顏色
width: 1, // 粗細(xì)
},
},
},
series: {
barWidth: 18,
itemStyle: {
barBorderRadius: [5, 5, 0, 0],
color: function(params) {
return _this.isMax(params.data) ? '#73A0FA' : '#5E6E8C';
}
},
label: {
show: true,
position: 'top',
fontFamily: 'DINCondensed-Bold',
color: function(params) {
return _this.isMax(params.data) ? '#73A0FA' : '#5E6E8C';
}
}
},
grid: {
top: 20,
left: 10,
right: 10,
bottom: 0,
},
// backgroundColor: 'red'
};
this.chartSettings1 = {
dimension:['name', 'rank'],
};
const colorList = ['#E83939', '#EC6B45', '#F4CA47', '#5E6E8C'];
this.chartExtend1 = {
// 標(biāo)題
title: {
show: true,
text: '單位:萬歐元',
right: 5,
textStyle: {
color: '#909090',
fontSize: 10,
fontFamily: 'PingFangSC-Regular',
}
},
// 顏色
color: colorList,
legend: {
show: false
},
tooltip: {
show: false
},
yAxis: {
splitLine: {show: false},
type : 'value',
axisLine: {
show: true,
lineStyle: {
fontSize: 14,
color: '#DADADA', // 顏色
width: 1, // 粗細(xì)
},
},
axisLabel: {
show: true,
color: '#A5A5A5',
fontSize: 8
}
},
// 隱藏右側(cè)y軸
'yAxis.1.axisLine': {
show: false
},
'xAxis.0.axisLabel': {
interval: 0,
color: '#303030',
fontSize: 12,
fontFamily: 'PingFangSC-Regular',
},
'xAxis.0.axisLine': {
show: true,
lineStyle: {
fontSize: 14,
color: '#DADADA', // 顏色
width: 1, // 粗細(xì)
},
},
'xAxis.1.axisLabel': {
interval: 0,
color: '#909090',
fontSize: 10,
fontFamily: 'PingFangSC-Regular',
},
'xAxis.1.axisLine': {
show: true,
lineStyle: {
fontSize: 14,
color: '#DADADA', // 顏色
width: 1, // 粗細(xì)
},
},
// 雙軸的位置 top | bottom
'xAxis.0.position': 'bottom',
'xAxis.1.position': 'bottom',
// x軸的位置相對偏移
'xAxis.1.offset': 15,
series: {
barWidth: 18,
itemStyle: {
barBorderRadius: [5, 5, 0, 0],
color: function(params) {
return colorList[params.dataIndex];
}
},
label: {
show: true,
position: 'top',
color: '#303030',
fontFamily: 'DINCondensed-Bold'
},
},
grid: {
top: 20,
left: 10,
right: 10,
bottom: 0,
},
// backgroundColor: 'red'
};
// 基準(zhǔn)線 | 平均值
this.markLine = {
symbol: 'none', // 標(biāo)線兩端的標(biāo)記類型
silent: true, // 圖形是否不響應(yīng)和觸發(fā)鼠標(biāo)事件
itemStyle: {
normal:{ show: true, color: '#E9E9E9'},
},
data:[
{
yAxis: 3302, // 平均值
label: { // 基準(zhǔn)線右側(cè)的value值
show: false
},
}
],
};
return {
analysePlayer: {
chartData: {
columns: ['name', 'value'],
rows: [
{ 'name': '貝克漢姆', 'value': 9970, 'rank': '第一名' },
{ 'name': '梅西', 'value': 9735, 'rank': '第二名' },
{ 'name': '奧斯卡', 'value': 5760, 'rank': '第三名' },
{ 'name': '球隊均值', 'value': 3302, 'rank': '' },
],
},
},
analyseGoal: {
chartData: {
columns: ['time', 'goalNum'],
rows: [
{ 'time': '0-15', 'goalNum': 1 },
{ 'time': '15-30', 'goalNum': 1 },
{ 'time': '30-45', 'goalNum': 0 },
{ 'time': '45+', 'goalNum': 2 },
{ 'time': '45-60', 'goalNum': 4 },
{ 'time': '60-75', 'goalNum': 1 },
{ 'time': '75-90', 'goalNum': 0 },
{ 'time': '90+', 'goalNum': 0 },
],
},
},
width: 0,
}
},
mounted() {
const _that = this;
setTimeout(() => {
_that.width = _that.$refs.boxRef.clientWidth || 0;
console.log('width:', _that.width)
}, 100)
},
methods: {
isMax(val) {
return !this.analyseGoal.chartData.rows.find(p => Number(p.goalNum) > Number(val));
}
}
}
</script>