Krishna Chaitanya
Krishna Chaitanya

Reputation: 27

Need a single border for stacked bar graph in Highcharts

I am getting a border for each data in a stacked bar graph.

ChartOptions :

Highcharts.chart('container', {
    chart: {
        type: 'bar'
    },
    title: {
        text: 'Stacked bar chart'
    },
    xAxis: {
        categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
    },
    yAxis: {
        min: 0,
        title: {
            text: 'Total fruit consumption'
        }
    },
    legend: {
        reversed: true
    },
    plotOptions: {
        series: {
            stacking: 'normal'
        }
    },
    series: [{
        name: 'John',
        data: [{
            y: 5,
          borderColor: 'red',
          borderWidth: 4
        }, 3, 4, 7, 2]
    }, {
        name: 'Jane',
        data: [{y: 2,
          borderColor: 'red',
          borderWidth: 4}, 2, 3, 2, 1]
    }, {[enter image description here][1]
        name: 'Joe',
        data: [{y: 3,
          borderColor: 'red',
          borderWidth: 4}, 4, 4, 2, 5]
    }]
});

codepen

I want something like this image

Kindly help me with the correct ChartOptions which gives a single border around the bar without multiple borders around each bar.

Thanks and Regards

Upvotes: 1

Views: 1039

Answers (2)

ppotaczek
ppotaczek

Reputation: 39069

You can add fake series with a border and update it dynamically depending on changes on the chart or render a custom shape to simulate borders.

    series: [..., {
        showInLegend: false,
        stacking: false,
        data: [10],
        grouping: false,
        color: 'transparent',
        borderWidth: 4,
        borderColor: 'red'
    }]

Live demo: http://jsfiddle.net/BlackLabel/gtLm9hqk/

API Reference:

https://api.highcharts.com/highcharts/series.column

https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#rect

Upvotes: 1

Marcello Perri
Marcello Perri

Reputation: 610

If you are trying to remove the red border, here is the solution:

Highcharts.chart('container', {
    chart: {
        type: 'bar'
    },
    title: {
        text: 'Stacked bar chart'
    },
    xAxis: {
        categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
    },
    yAxis: {
        min: 0,
        title: {
            text: 'Total fruit consumption'
        }
    },
    legend: {
        reversed: true
    },
    plotOptions: {
        series: {
            stacking: 'normal'
        }
    },
    series: [{
        name: 'John',
        data: [{
            y: 5,
          borderWidth: 1
        }, 3, 4, 7, 2]
    }, {
        name: 'Jane',
        data: [{
          y: 2,
          borderWidth: 1}, 2, 3, 2, 1]
    }, {
        name: 'Joe',
        data: [{
          y: 3,
          borderWidth: 1}, 4, 4, 2, 5]
    }]
});

Upvotes: 0

Related Questions