简体   繁体   English

高图堆积百分比柱形图可以小于100%

[英]Can highcharts stacked percentage column chart be less than 100%

I have a requirement to have a stacked percentage column chart in highcharts display a breakdown of a specific percentage number rather than a breakdown of 100%. 我要求在高图中堆积百分比的柱形图显示特定百分比数字的细分,而不是100%的细分。 For example, if the number is 60%, the graph should show a breakdown of 60% (20% blue, 10% green, 30% yellow) rather than fill up to 100%. 例如,如果数字为60%,则图表应显示60%的细分(20%的蓝色,10%的绿色,30%的黄色),而不是填充到100%。 My understanding of percentage charts is they are always 100%, but wondering if this kind of manipulation is possible with highcharts somehow? 我对百分比图的理解是它们始终是100%,但是想知道通过高图可以进行这种操纵吗? Thanks. 谢谢。

Use Stacked column instead of stacked percentage column, then simply append a percent to your label. 使用堆积列而不是堆积百分比列,然后将百分比附加到标签上即可。 Percentage column automatically determines the percentages of all data points provided, it sounds like you want the column to instead simply render the provided information. 百分比列自动确定所提供的所有数据点的百分比,这听起来像您希望该列只是呈现所提供的信息。

Like what @Alden Be said, use stacked column with % labels. 就像@Alden Be所说的那样,使用带有%标签的堆叠列。 Here is the JSFiddle example . 这是JSFiddle示例

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: 'Stacked column chart'
        },
        xAxis: {
            categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas'] 
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Percentage'
            },
            labels: {
                formatter: function () {
                    return this.value + '%';
                }
            },
            stackLabels: {
                enabled: true,
                style: {
                    fontWeight: 'bold',
                    color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
                },
                formatter: function () {
                    return this.total + '%';
                }
            }
        },
        legend: {
            align: 'right',
            x: -30,
            verticalAlign: 'top',
            y: 25,
            floating: true,
            backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
            borderColor: '#CCC',
            borderWidth: 1,
            shadow: false
        },
        tooltip: {
            headerFormat: '<b>{point.x}</b><br/>',
            pointFormat: '{series.name}: {point.y}%<br/>Total: {point.stackTotal}%'
        },
        plotOptions: {
            column: {
                stacking: 'normal',
                dataLabels: {
                    enabled: true,
                    format:'{y}%',
                    color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
                    style: {
                        textShadow: '0 0 3px black'
                    }
                }
            }
        },
        series: [{
            name: 'John',
            data: [5, 3, 4, 7, 2]
        }, {
            name: 'Jane',
            data: [2, 2, 3, 2, 1]
        }, {
            name: 'Joe',
            data: [3, 4, 4, 2, 5]
        }]
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM