echarts——柱状图设置——技能提升
今天做了一个柱状图,是通过echarts
来处理的。
效果图如下所示:
查看上面的效果图:可以看出有几个需要设置的部分
1. y
轴上方有个单位:个
,这个可以通过y
轴设置参数中添加一个name
来实现,还有位置设置
2. x
轴和y
轴的刻度线隐藏,坐标轴颜色和文字颜色设置,柱状图区域背景线为虚线
3. 柱状图形有圆角,且两个柱子之间有间距
下面分别详细记录一下:
1. y
轴上方有个单位:个
,这个可以通过y
轴设置参数中添加一个name
来实现,还有位置设置
yAxis: {
type: 'value',
name: '单位:个',
nameTextStyle: {
color: "#1A1A1A",
padding:[0,-60,0,0],
},
axisLabel: {
textStyle: {
color: '#999999'
}
},
axisLine: {
lineStyle: {
type: 'solid',
color: '#CCCCCC'
}
},
axisTick: {
show: false
},
splitLine: {
show: true,
lineStyle: {
type:'dashed'
}
}
},
上面代码中的name
就是单位,nameTextStyle
可以设置name
的颜色和位置。padding
有四个参数,可以测试一下,就知道该用哪几个参数了
name: '单位:个',
nameTextStyle: {
color: "#1A1A1A",
padding:[0,-60,0,0],
},
2. x
轴和y
轴的刻度线隐藏,坐标轴颜色和文字颜色设置
以y
轴为例
yAxis: {
type: 'value',
name: '单位:个',
nameTextStyle: {
color: "#1A1A1A",
padding:[0,-60,0,0],
},
axisLabel: {
textStyle: {
color: '#999999'
}
},
axisLine: {
lineStyle: {
type: 'solid',
color: '#CCCCCC'
}
},
axisTick: {
show: false
},
splitLine: {
show: true,
lineStyle: {
type:'dashed'
}
}
},
坐标轴文字设置
axisLabel: {
textStyle: {
color: '#999999'
}
},
坐标轴线设置
axisLine: {
lineStyle: {
type: 'solid',
color: '#CCCCCC'
}
},
坐标轴刻度线设置
axisTick: {
show: false,//隐藏,不显示
},
设置柱状图区域背景为虚线
splitLine: {
show: true,
lineStyle: {
type:'dashed'
}
}
3.柱状图形有圆角,且两个柱子之间有间距
series:[{
data: [120, 700, 150, 480, 70, 110, 130],
type: 'bar',
barGap:0.5,
label: {
normal: {
show: true,
position:'top',
formatter:'{c}'
}
},
barWidth: 12,
itemStyle: {
normal: {
barBorderRadius: [6],
}
}
}]
展示数值
label: {
normal: {
show: true,
position:'top',
formatter:'{c}'
}
},
设置柱子的宽度
barWidth: 12,
设置柱子圆角
itemStyle: {
normal: {
barBorderRadius: [6],
}
}
设置两个柱子之间的间距
barGap:0.5,
还没有评论,来说两句吧...