echarts柱状图铺满_使用echarts画百分比排名柱状图

使用echarts画排名信息,可以保证在固定大小的容器中完美展现,不会出现文字和图画越界问题。

效果图:

image.png

/**

* 画占比图

* @param {String} container 容器

* @param {JSON} yData Y轴数据

* @param {JSON} ratio 占比数据

* @param {JSON} surplus 剩余数据

*/

function drawPercentage(container, yData, ratio, surplus) {

var myChart = echarts.init(document.getElementById(container));

var option = {

grid: {

left: '8%',

right: '8%',

bottom: '4%',

top: 10,

containLabel: true

},

xAxis: {

show: false

},

yAxis: {

type: 'category',

inverse: true,

//城市名称

data: yData,

axisTick: {

show: false

},

axisLine: {

show: false

},

axisLabel: {

show: true,

color: function (value, index) {

if(index == 0) {

return 'red';

}

if(index == 1) {

return '#ff8447';

}

if(index == 2) {

return '#ffcc00';

}

return 'rgb(18,205,12)'

},

fontSize: 15,

fontWeight: 'bold'

},

},

series: [

{

type: 'bar',

stack: 'chart',

z: 3,

barWidth: '20',

itemStyle: {

normal: {

color: new echarts.graphic.LinearGradient(1,

0, 0, 1, [{

offset: 0,

color: '#2A6BCD'

}, {

offset: 1,

color: '#34F6F8'

}])

}

},

label: {

normal: {

position: 'right',

show: true,

color: 'white',

formatter: '{c}%'

}

},

data: ratio

},

{

type: 'bar',

stack: 'chart',

barWidth: '20',

itemStyle: {

normal: {

color: '#0D2253'

}

},

data: surplus

}]

}

myChart.setOption(option);

}

调用方式:

var yData = ["河北", "北京", "天津", "河南", "山东", "内蒙", "宁夏", "陕西", "四川", "湖南"];

//百分比数据

var ratio = [45, 12, 10, 7, 6, 5, 5, 4, 3, 2];

//100%-ratio

var surplus = [55, 88, 90, 93, 94, 95, 95, 96, 97, 98];

drawPercentage('regionDetail', yData, ratio, surplus);

关于柱状图的颜色过度和颜色配置,可以在series中调整。

关于排名文字信息样式可以在yAxis中的axisLabel里面设置,而且可以根据排名设置字体不同的颜色。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值