Highcharts Stacked Bar:如何删除栏之间的间距

时间:2014-10-10 13:49:21

标签: highcharts

我正在使用highcharts堆叠条,想要删除条形图之间的空间,这样我就可以为我正在渲染的文本腾出空间。

我尝试过pointPadding和groupPadding,但这些都没有用。我在xAxis上尝试了minPadding / maxPadding,并且没有做任何事情。

似乎摆脱那个空间的唯一方法是改变整个图表的宽度,这是我真正不想要的。

这是我的小提琴:

http://jsfiddle.net/nick1572/dfcysj39/

$("#profit-chart").highcharts({

        lang: {
            thousandsSep: ","
        },
        chart: {
            type: "column",
            style: {
                fontFamily: "Open Sans, sans-serif"
            }
        },
        legend: {
            enabled: false
        },
        title: {
            text: ""
        },
        xAxis: {
            //minPadding: 20, Not working here
            //maxPadding:1, Not working here either

            categories: [ "other business", "somekind of business profit" ],
            labels: {
                style: {
                    color: "#333333",
                    fontSize: "15px"
                }
            }
        },
        yAxis: {
            gridLineDashStyle: "longdash",
            title: {
                text: "Dollars"
            },
            labels: {
                enabled: true,
                formatter: function() {
                    return "$" + Highcharts.numberFormat(this.value, 0, "", ",");
                }
            }
        },
        tooltip: {
            enabled: false
        },
        plotOptions: {


            column: {
                stacking: "normal",
                dataLabels: {
                    enabled: true,
                    color: "white",
                    inside: true,
                    useHTML: true,
                    style: {
                        fontSize: "18px",
                        fontWeight: "600"
                    }
                }
            },
            series: {
                //pointPadding: 0,
                //groupPadding: 0, this does not work
                animation: {
                    complete: function() {

                    }
                },

                 pointWidth: 145
            }
        },

        series: [ {
            color: "#327631",
            data: [ 0, 850 ],
            stack: "female",
            dataLabels: {
                enabled: true,
                formatter: function() {
                    if (0 != this.y) return "$" + Highcharts.numberFormat(this.y, 0); 


                    else return null;
                }
            }

            }, {
            color: "#ADC9AD ",
            data: [ 10000, 10000 ],
            stack: "female",
            dataLabels: {
                enabled: true,
                formatter: function() {
                    return "$" + Highcharts.numberFormat(this.y, 0);
                }
            }
        }]

        },

        function (chart) { // on complete

                chart.renderer.text('<span class="bracketed">}</span>  <em>Profit</em>', 870, 85)
                    .css({
                        color: 'green',
                        fontSize: '24px',
                        x: 200
                    })
                    .add();


    });//End HighCharts Call 

提前致谢!

2 个答案:

答案 0 :(得分:0)

似乎点宽度设置与groupPadding和pointPadding相冲突..如果删除系列中的pointWidth: 145并将groupPadding和pointPadding添加到列中,则会删除间隙。然而,在反面,条形将占据图表的整个可用宽度。

 column: {
         stacking: "normal",
         groupPadding: 0,//add here
         pointPadding: 0,//add here
         ...
}

http://jsfiddle.net/dfcysj39/9/

答案 1 :(得分:0)

好的,所以我认为这可能会解决我的问题。不确定它是否正确但是有效。 pointPadding和groupPadding部分适用于此特定问题。我感谢Birgit花时间回复!!!

我要解决这个问题的方法是在图表上明确地设置一个spacingRight,以便为绘图区域提供更多的空间,而不会使条形更宽。我确实回过头来添加一些pointPadding,使cols稍微宽一点,以达到美观。这允许显示渲染的文本。

http://jsfiddle.net/nick1572/dfcysj39/

$("#profit-chart").highcharts({

        lang: {
            thousandsSep: ","
        },
        chart: {
            spacingRight: 220,
            type: "column",
            width: 1200,
            style: {
                fontFamily: "Open Sans, sans-serif"
            }
        },
        legend: {
            enabled: false
        },
        title: {
            text: ""
        },
        xAxis: {
            //minPadding: 20, Not working here
            //maxPadding:1, Not working here either
            categories: [ "other business", "somekind of business profit" ],
            labels: {
                style: {
                    color: "#333333",
                    fontSize: "15px"
                }
            }
        },
        yAxis: {
            gridLineDashStyle: "longdash",
            title: {
                text: "Dollars"
            },
            labels: {
                enabled: true,
                formatter: function() {
                    return "$" + Highcharts.numberFormat(this.value, 0, "", ",");
                }
            }
        },
        tooltip: {
            enabled: false
        },
        plotOptions: {


            column: {
                stacking: "normal",
                dataLabels: {
                    enabled: true,
                    color: "white",
                    inside: true,
                    useHTML: true,
                    style: {
                        fontSize: "18px",
                        fontWeight: "600"
                    }
                }
            },
            series: {
                pointPadding: 0.05,
                //groupPadding: 0, this does not work
                animation: {
                    complete: function() {

                    }
                }//,

                 //pointWidth: 145
            }
        },

        series: [ {
            color: "#327631",
            data: [ 0, 850 ],
            stack: "female",
            dataLabels: {
                enabled: true,
                formatter: function() {
                    if (0 != this.y) return "$" + Highcharts.numberFormat(this.y, 0); 


                    else return null;
                }
            }

            }, {
            color: "#ADC9AD ",
            data: [ 10000, 10000 ],
            stack: "female",
            dataLabels: {
                enabled: true,
                formatter: function() {
                    return "$" + Highcharts.numberFormat(this.y, 0);
                }
            }
        }]

        },

        function (chart) { // on complete

                chart.renderer.text('<span class="bracketed">}</span>  <em>Profit</em>', 900, 84)
                    .css({
                        color: 'green',
                        fontSize: '24px',
                        x: 200
                    })
                    .add();


    });//End HighCharts Call