echarts正负坐标轴柱子渐变

echarts正负坐标轴柱子渐变正负坐标轴柱子渐变效果图

关键代码:

//负轴样式
var  itemStyle1  =  {
                                                normal:{
                                                        color:  new  echarts.graphic.LinearGradient(1,  0,  0,  0,  [{
                                                                offset:  0,
                                                                color:  "#266E6F"  //  0%  处的颜色
                                                        },  
                                                          {
                                                                offset:  1,
                                                                color:  "#51E2D5"  //  100%  处的颜色
                                                        }],  false),
                                                label:  {
                        show:  true,  //开启显示
                        position:  'top',  //在上方显示
                        textStyle:  {  //数值样式
                color:  '#687284',
                fontSize:  9,
                }
                }
                                        }
                                };
//正轴样式
var  itemStyle2  =  {
                                normal:{
                                        color:  new  echarts.graphic.LinearGradient(1,  0,  0,  0,  [{
                                                offset:  0,
                                                color:  "#642925"  //  0%  处的颜色
                                        },  
                                          {
                                                offset:  1,
                                                color:  "#EA4824"  //  100%  处的颜色
                                        }],  false),
                                label:  {
                show:  true,  //开启显示
                position:  'top',  //在上方显示
                textStyle:  {  //数值样式
        color:  '#687284',
        fontSize:  9,
        }
        }
                                }
                                }

在option中的位置

series  :  [
                {
                        name:'生活费',
                        type:'bar',
                        stack:  '总量',
                        label:  {
                                normal:  {
                                        show:  true,
                                        formatter:  '{b}'
                                }
                        },
                        data:[
                                {      value:  -0.07,  
                                        label:  labelleft,
                                        itemStyle:itemStyle1
                                },
                                {
                                     value: -0.09, 
          label: labelleft,
          itemStyle:itemStyle1
        },
        {   
         value: 0.2,
         label: labelRight,
         itemStyle:itemStyle2
         
        }
       ]
    }
   ]

完整代码示例(将代码放在echarts官网示例上可直接看效果):

var  labelleft  =  {
        normal:  {
                position:  'left'
        }
};
var  labelRight  =  {
        normal:  {
                position:  'right'
        }
};
//负轴样式
var  itemStyle1  =  {
                                                normal:{
                                                        color:  new  echarts.graphic.LinearGradient(1,  0,  0,  0,  [{
                                                                offset:  0,
                                                                color:  "#266E6F"  //  0%  处的颜色
                                                        },  
                                                          {
                                                                offset:  1,
                                                                color:  "#51E2D5"  //  100%  处的颜色
                                                        }],  false),
                                                label:  {
                        show:  true,  //开启显示
                        position:  'top',  //在上方显示
                        textStyle:  {  //数值样式
                color:  '#687284',
                fontSize:  9,
                }
                }
                                        }
                                };
//正轴样式
var  itemStyle2  =  {
                                normal:{
                                        color:  new  echarts.graphic.LinearGradient(1,  0,  0,  0,  [{
                                                offset:  0,
                                                color:  "#642925"  //  0%  处的颜色
                                        },  
                                          {
                                                offset:  1,
                                                color:  "#EA4824"  //  100%  处的颜色
                                        }],  false),
                                label:  {
                show:  true,  //开启显示
                position:  'top',  //在上方显示
                textStyle:  {  //数值样式
        color:  '#687284',
        fontSize:  9,
        }
        }
                                }
                                }
option  =  {
        title:  {
                text:  '交错正负轴标签',
                subtext:  'From  ExcelHome',
              //  sublink:  'http://e.weibo.com/1341556070/AjwF2AgQm'
        },
        tooltip  :  {
                trigger:  'axis',
                axisPointer  :  {                        //  坐标轴指示器,坐标轴触发有效
                        show:false,
                        type  :  'shadow'              //  默认为直线,可选为:'line'  |  'shadow'
                }
        },
        grid:  {
                top:  80,
                bottom:  30
        },
        xAxis:  {
                type  :  'value',
                axisLine:  {show:  false},
                axisLabel:  {show:  false},
                axisTick:  {show:  false},
                splitLine:  {show:  false},
                position:  'left',
          //      splitLine:  {lineStyle:{type:'dashed'}},
        },
        yAxis:  {
                type  :  'category',
                show:true,
                position:  'left',
                axisLine:  {show:  true},
                axisLabel:  {show:  true},
                axisTick:  {show:  false},
                splitLine:  {show:  false},
                data  :  ['ten',  'nine',  'eight',  'seven',  'six',  'five',  'four',  'three',  'two',  'one']
        },
        series  :  [
                {
                        name:'生活费',
                        type:'bar',
                        stack:  '总量',
                        label:  {
                                normal:  {
                                        show:  true,
                                        formatter:  '{b}'
                                }
                        },
                        data:[
                                {      value:  -0.07,  
                                        label:  labelleft,
                                        itemStyle:itemStyle1
                                },
                                {
                                     value: -0.09, 
                    label: labelleft,
                    itemStyle:itemStyle1
            },
            {   
                value: 0.2,
                label: labelRight,
                itemStyle:itemStyle2
                
            },{
                    value: 0.44,
                    label: labelRight,
                     itemStyle:itemStyle2
                
            } ,{
                    value: -0.23, 
                    label: labelleft,
                    itemStyle:itemStyle1
            },{
                    value: 0.08,
                    label: labelRight,
                     itemStyle:itemStyle2
            },{
                    value: -0.17, 
                    label: labelleft,
                    itemStyle:itemStyle1
            },{
                    value: 0.47,
                    label: labelRight,
                     itemStyle:itemStyle2
            },{ 
                
                    value: -0.36, 
                    label: labelleft,
                    itemStyle:itemStyle1
           },{
                    value: 0.18,
                    label: labelRight,
                     itemStyle:itemStyle2
           }
            ]
        }
    ]
};
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值