echart 堆叠柱状图而不重叠,总数不会叠加,显示百分比

本文介绍了如何在Echarts中创建堆叠柱状图,确保柱状不重叠,并展示每个柱子的百分比比例,同时强调了配置过程中需避免与stack属性冲突。
<!DOCTYPE html>
<html style="height: 100%">
   <head>
       <meta charset="utf-8">
   </head>
   <body style="height: 100%; margin: 0">
       <div id="container" style="height: 100%"></div>
       <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/echarts.min.js"></script>
       <script type="text/javascript">
        var dataX = ['大类案件', '小类案件','自行处置案件 '];
        var dataY = [100,100,50];
        var dataY2 = [50,48,10]
        var dom = document.getElementById("container");
        var myChart = echarts.init(dom);
        option = {
              xAxis: {
                  type: 'category',
                  data: dataY,
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: '#000'
                        }
                    },
                    axisLine: {
                        show: false
                    },
                    axisTick: {
                        show: false
                    },
              },
              yAxis: {
                  type: 'value',
                    splitLine:{
                        show: true,
                        color: '#ccc'
                    },//去除网格线
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: '#000'
                        }
                    },
                    axisLine: {
                        show: false
                    },
                    axisTick: {
                        show: false
                    },
              },
              series : [
                  {
                      type:'bar',
                      data:dataY,
                      barGap: '-100%',//添加此配置项即为重叠效果
                        itemStyle: {
                          normal: {
                            color:'#f5e181',
                            label : {
                              show: true,
                              position: 'top',
                              formatter: function (params) {
                                     return params.value ;
                                  },
                              textStyle: {
                                color: '#000', 
                                fontSize:'18'
                              }
                            }
                          }
                        }
                  },
                  {
                      type:'bar',
                      data:dataY2,
                       itemStyle: {
                          normal: {
                            color:'#fdcf0e',
                            label : {
                              show: true,
                              position: 'insideTop',
                              formatter: function (params,index) {
                                 return params.value == 0 ? '0%' : Math.round(params.value/dataY2[params.dataIndex]*1000)/10 + '%';
                              },
                              textStyle: {
                                color: '#000', 
                                fontSize:'18'
                              }
                            }
                          }
                        }
                  },
                  
              ]
          };
          myChart.setOption(option, true);
       </script>
   </body>
</html>

注意点:不能跟stack属性一起用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值