highcharts带负值的双坐标柱状图

双坐标 负值 柱状图

想要的效果:
在这里插入图片描述
代码

       chart = Highcharts.chart('Funds_to_adjust', {
            chart: {
                type: 'bar',
                marginLeft:70,				//画板左右两侧边距
                marginRight:80			//画板左右两侧边距
            },
            credits: {
                enabled: false  // 禁用版权信息
            },
            title: {
                text: null
            },
            subtitle: {
                text: null
            },
            plotOptions: {
                column: {
                    pointPadding: 0.4,
                    borderWidth: 0,
                    pointWidth: 30
                }
            },
            xAxis: [{
                categories: [' '],
                title:{
                    text:null
                },
                crosshair: true,
                showEmpty:true
            }],
            yAxis: [{
                allowDecimals: false,
                tickWidth:1,
                labels: {
                    format: '{value}',
                    style: {
                        color: Highcharts.getOptions().colors[1]
                    }
                },
                title: {
                    text: '项目数量',
                    style: {
                        color: Highcharts.getOptions().colors[1]
                    },
                    align:'high',								//和坐标轴的最大值对齐
                    y:20,
                    x:70
                },
                opposite: true										//和坐标轴的最大值对齐,可用的值有 "low","middle" 和 "high"
            }, {
                labels: {
                    format: '{value}',
                    style: {
                        color: Highcharts.getOptions().colors[0]
                    }
                },
                title: {
                    text: '预算金额',
                    style: {
                        color: Highcharts.getOptions().colors[0]
                    },
                    align:'high',								//和坐标轴的最大值对齐,可用的值有 "low","middle" 和 "high"
                    y:-20,
                    x:70
                }
            }],
            tooltip: {
                useHTML: true,
                formatter: function (data) {
                    if (this.series.name == "新增项目") {
                        return '<span>' + this.series.name + '</span><br/>' + '项目' +'<span><span>    </span><strong>'+ this.y + '</strong></span><span>    </span>'+ '预算' +'<span><span>    </span><strong>'+ this.series.chart.series[2].yData + '</strong></span>';
                    } else if (this.series.name == "取消项目") {
                        return '<span>' + this.series.name + '</span><br/>' + '项目' +'<span><span>    </span><strong>'+ (-(this.y)) + '</strong></span><span>    </span>' + '预算' +'<span><span>    </span><strong>'+ (-(this.series.chart.series[3].yData)) + '</strong></span>';
                    } else if (this.series.name == "调整项目(调增)") {
                        return '<span>' + this.series.name + '</span><br/>'  + '项目' +'<span><span>    <span><strong>'+ this.series.chart.series[0].yData + '</strong></span><span>    </span>' + '预算' +'<span><span>    </span><strong>'+ this.series.chart.series[2].yData + '</strong></span>';
                    } else if (this.series.name == "调整项目(调减)") {
                        return '<span>' + this.series.name + '</span><br/>' + '项目' +'<span><span>    <span><strong>'+(-(this.series.chart.series[1].yData)) + '</strong></span><span>    </span>' + '预算' +'<span><span>    </span><strong>'+(-(this.series.chart.series[3].yData)) + '</strong></span>';
                    }
                }
            },
            legend: {
                layout: 'horizontal',
                align: 'center',
                x: 0,
                y:-15,
                verticalAlign: 'top',
                floating: true,
                backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
            },
            series: [{ 
            name: '新增项目',
            color: '#3367EF',
            data: [6],
            tooltip: {
                  valueSuffix: '个'
                  }
                  },
            {
            name: '取消项目',
            color: '#C1D1FA',
            data: [-6],
            tooltip: {
            			valueSuffix: '个'
            },},
            {
            name: '调整项目(调增)',
            yAxis: 1,
            color: '#05AD35',
            data: [1200],
            tooltip: {
            valueSuffix: '万'
            }},
            {
            name: '调整项目(调减)',
            yAxis: 1,
            color: '#B4E6C2',
            data: [-1200],
            tooltip: {
            valueSuffix: '万'
             }
            }]
        });

详细参数配置请参照官方文档:highcharts官方:https://api.highcharts.com.cn/highcharts

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值