AntVG2柱状图改变柱⼦颜⾊+柱⼦上⽅显⽰⽂字与图标AntV G2,对柱状图进⾏⼀些⾃定义:
1.柱⼦颜⾊⾃定义
2.柱⼦上⽅显⽰⽂本
3.柱⼦上⽅显⽰图标
具体代码如下:
<template>
<div id="mountNode"></div>
</template>
<script>
import G2 from '@antv/g2'
export default {
name: "antv",
mounted () {
this.drawBar()
},
methods:{
drawBar(){
var data = [{
"name": "John",上海英孚教育怎么样
"vote": 88
}, {
"name": "Damon",
"vote": 56
}, {
"name": "Patrick",
"vote": 92
}, {
"name": "Mark",
"vote": 83
},{
"name": "Lo",性别 英语
"vote": 43thinfilm
"vote": 43
},{
"name": "Kii",
外国名著"vote": 99
同声传译价格表}];
var imageMap = {
'excellent': '/rmsportal/mYhpaYHyHhjYcQf.png', 'good': '/rmsportal/JBxkqlzhrlkGlLW.png',
'bad': '/rmsportal/zlkGnEMgOawcyeX.png',
};
var chart = new G2.Chart({
container: 'mountNode',
//forceFit:true时宽度配置不⽣效
width:1000,
height: 600,
padding: [60, 20, 40, 60],
});
chart.source(data, {
vote: {
min: 0
}
});
d({
transpod: true
});
chart.legend(fal);
chart.axis('vote', {
labels: null,
title: null,
line: null,
tickLine: null,
});
guanchart.interval().position('name*vote').color('name*vote', function (name,vote) { if (vote > 90) {
return '#db4c3c'
} el if (vote > 60) {
return '#fec514'
} el {
return '#7f8da9'
}
});
chart
.point()
.position('name*vote')
.size(60)
.shape('name*vote', function(name,vote) {
if (vote > 90) {
普特英语听力论坛
return ['image', imageMap['excellent']];
} el if (vote > 60) {
a biscuitreturn ['image', imageMap['good']];
} el {kona
return ['image', imageMap['bad']];
}
})
.label('vote',{
offt: -20, // ⽂本距离图形的距离
offt: -20, // ⽂本距离图形的距离 textStyle: {
fill: '#404040',
fontSize:'14',
fontWeight: 'bold', // ⽂本粗细 shadowBlur: 5, // ⽂本阴影模糊 shadowColor: '#fff' // 阴影颜⾊ },
formatter:function (value) {
if (value > 90) {
return '优秀'
} el if (value > 60) {
return '良好'
} el {
return '不达标'
}
}
});
}
}
}
</script>
<style scoped>
</style>