Joe W
Joe W

Reputation: 2891

Add border on highcharts bar chart on start of bar

I have a bar chart created in highcharts with a border around all of the bar. However, I've disabled the grid lines and tick marks. I would like for the whole bar to be enclosed in a border including the left most edge of the bar. Is it possible to add the border on that portion of the bar? You can see my chart here:

http://jsfiddle.net/9csjzsx5/

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'bar',
            width: 265,
            height: 350
        },
        credits: {
            text: ''
        },
        title: {
            text: ''
        },
        xAxis: {
            labels: {
                align: 'left',
                x: 0,
                y: -12
            },
            tickWidth: 0,
            lineWidth: 0,
            minorGridLineWidth: 0,            
            categories: ['Label 1', 'Label 2', 'Label 3', 'Label 4', 'Label 5', 'Label 6', 'Label 7', 'Label 8', 'Label 9']
        },
        yAxis: {

            minorGridLineWidth: 0,
            majorGridLineWidth: 0,

            gridLineWidth: 0,
            labels: {
                enabled: false
            },
            title: {
                text: '',
                align: 'high'
            },
            tickWidth: 0
        },
        plotOptions: {
            bar: {
                colorByPoint: true,
                colors: ['#4572A7', '#AA4643', '#89A54E', '#80699B', '#3D96AE', '#DB843D', '#92A8CD', '#A47D7C', '#B5CA92']
            },
            series: {
                stacking: 'normal',
                borderColor: '#303030'
            }
        },
        series: [{
            data: [{
                dataLabels: {
                    enabled: true,
                    defer: false,
                    align: 'right',
                    color: 'black',
                    x: 0,
                    format: '{y}%',
                    style: {
                        fontSize: '12px',
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black',
                    }
                },
                y: 9,
                color: 'white'
            }, {
                dataLabels: {
                    enabled: true,
                    defer: false,
                    align: 'right',
                    color: 'black',
                    x: 0,
                    format: '{y}%',
                    style: {
                        fontSize: '12px',
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black',
                    }
                },
                y: 9,
                color: 'white'
            }, {
                dataLabels: {
                    enabled: true,
                    defer: false,
                    align: 'right',
                    color: 'black',
                    x: 0,
                    format: '{y}%',
                    style: {
                        fontSize: '12px',
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black',
                    }
                },
                y: 8,
                color: 'white'
            }, {
                dataLabels: {
                    enabled: true,
                    defer: false,
                    align: 'right',
                    color: 'black',
                    x: 0,
                    format: '{y}%',
                    style: {
                        fontSize: '12px',
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black',
                    }
                },
                y: 9,
                color: 'white'
            }, {
                dataLabels: {
                    enabled: true,
                    defer: false,
                    align: 'right',
                    color: 'black',
                    x: 0,
                    format: '{point.name}%',
                    style: {
                        fontSize: '12px',
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black',
                    }
                },
                y: 10,
                name: '<0.001',
                color: 'white'
            }, {
                dataLabels: {
                    enabled: true,
                    defer: false,
                    align: 'right',
                    color: 'black',
                    x: 0,
                    format: '{point.name}%',
                    style: {
                        fontSize: '12px',
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black',
                    }
                },
                y: 10,
                name: '<0.001',
                color: 'white'
            }, {
                dataLabels: {
                    enabled: true,
                    defer: false,
                    align: 'right',
                    color: 'black',
                    x: 0,
                    format: '{point.name}%',
                    style: {
                        fontSize: '12px',
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black',
                    }
                },
                y: 10,
                name: '<0.001',
                color: 'white'
            }, {
                dataLabels: {
                    enabled: true,
                    defer: false,
                    align: 'right',
                    color: 'black',
                    x: 0,
                    format: '{point.name}%',
                    style: {
                        fontSize: '12px',
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black',
                    }
                },
                y: 10,
                name: '<0.001',
                color: 'white'
            }, {
                dataLabels: {
                    enabled: true,
                    defer: false,
                    align: 'right',
                    color: 'black',
                    x: 0,
                    format: '{point.name}%',
                    style: {
                        fontSize: '12px',
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black',
                    }
                },
                y: 10,
                name: '<0.001',
                color: 'white'
            }],
            showInLegend: false,
            pointWidth: 15,
        }, {
            data: [2, 2, 3, 2, 1, 1, 1, 1, 1],
            showInLegend: false,
            pointWidth: 15,
        }]
    });
});

The missing border is especially apparent on the bottom colors but when it is printed it is visible on all of them.

Upvotes: 1

Views: 3660

Answers (1)

jlbriggs
jlbriggs

Reputation: 17791

The border is actually there, but is hidden beyond the axis min, it seems.

If you set a min as slightly less then zero, and set startOnTick to false, the border will appear:

yAxis: {
 min:-.1,
 startOnTick:false,
} 

Upvotes: 3

Related Questions