先上图片,今天在使用bizcharts的折线图统计数据的时候发现当坐标系的值设为小数或者字符串的时候,坐标系上面的文本会颠倒位置
// 折线图数据
//mock一下data数据
const linedata = [];
let arr=[1,0.2,0.3,0.8,0.8,0.9,0.9,0.9,0.4,0.4,0.5,0.6,0.7,0.3,0.5]
for(let i=14;i>=0;i--){
let date = moment().add(-i, 'day').format('YYYY-MM-DD');
linedata.push({
date: moment().add(-i, 'day').format('MM-DD'),
number:arr[i]
})
}
const linecols = {
number: {
min: 0,
range: [0, 0.93],
alias: '出勤率'
},
date: {
range: [0, 0.9],
alias: '时间'
}
};
<Col span={12}>
<span style={{fontWeight:"bold"}}>本月出勤率统计</span>
<div>
<Chart height={350} data={linedata} scale={linecols} forceFit>
<Axis name="date" title={{
position: 'end',
offset: 15,
textStyle: {
fontSize: '12',
textAlign: 'center',
fill: '#999',
fontWeight: 'bold',
rotate: 0,
autoRotate: true
}
}} />
<Axis name="number" title={{
position: 'end',
offset: 5.5,
textStyle: {
fontSize: '12',
textAlign: 'right',
fill: '#999',
fontWeight: 'bold',
rotate: 0
}
}}
label={{
autoRotate:false
}} />
<Tooltip
crosshairs={{
type: "y"
}}
/>
<Geom type="line" position="date*number" size={2}
tooltip={['date*number', (date, number) => {
return {
name: '出勤率', // 要显示的名字
value: (number*100).toFixed(1)+"%",
title: date
}
}]} />
<Geom
type="point"
position="date*number"
size={4}
shape={"circle"}
style={{
stroke: "#fff",
lineWidth: 1
}}
tooltip={['date*number', (date, number) => {
return {
name: '出勤率', // 要显示的名字
value: (number*100).toFixed(1)+"%",
title: date
}
}]}
/>
</Chart>
</div>
</Col>
百度搜索一下发现关于bizcharts的解答太少了,终于在查阅了官方文档之后,在y坐标的label属性里面设置autoRotate:false,即把自动旋转设为flase
<Axis name="number" title={{
position: 'end',
offset: 5.5,
textStyle: {
fontSize: '12',
textAlign: 'right',
fill: '#999',
fontWeight: 'bold',
rotate: 0
}
}}
label={{
autoRotate:false
}} />
终于解决了问题,在这里记录一下。