Andreas Köberle
Andreas Köberle

Reputation: 110892

Highcharts column chart with two different scales

Is there a way to have a column chart with two different scales. I have played with the example from highcharts but the result is still not perfect: https://jsfiddle.net/dfq4b6xz/

The problem is that the columns are not in the center of there each section

enter image description here

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: 'Efficiency Optimization by Branch'
        },
        xAxis: {
            categories: [
                'cat1',
                'cat2',
                'cat3'
            ]
        },
        yAxis: [{
            min: 0,
            title: {
                text: 'Employees'
            }
        }, {
            title: {
                text: 'Profit (millions)'
            },
            opposite: true
        }],
        legend: {
            shadow: false
        },
        tooltip: {
            shared: true
        },
        plotOptions: {
            column: {
                grouping: false,
                shadow: false,
                borderWidth: 0
            }
        },
        series: [{
            name: 'Employees',
            color: 'rgba(165,170,217,1)',
            data: [150, 73],
            pointPadding: 0.3,
            pointPlacement: -0.2
        }, {
            name: 'Employees Optimized',
            color: 'rgba(126,86,134,.9)',
            data: [140, 90],
            pointPadding: 0.4,
            pointPlacement: -0.2
        }, {
            name: 'Profit',
            color: 'rgba(248,161,63,1)',
            data: [null,null, 198.5],
            tooltip: {
                valuePrefix: '$',
                valueSuffix: ' M'
            },
            pointPadding: 0.3,
            pointPlacement: 0.2,
            yAxis: 1
        }, {
            name: 'Profit Optimized',
            color: 'rgba(186,60,61,.9)',
            data: [null,null, 208.5],
            tooltip: {
                valuePrefix: '$',
                valueSuffix: ' M'
            },
            pointPadding: 0.4,
            pointPlacement: 0.2,
            yAxis: 1
        }]
    });
});

Upvotes: 0

Views: 793

Answers (2)

jlbriggs
jlbriggs

Reputation: 17791

You are specifically telling the chart to place the points in that manner, using the pointPlacement property:

pointPlacement: 0.2

and

pointPlacement: -0.2

Remove those lines altogether, and it works as it should:

[[EDIT - Pawel answered while I was typing my answer... same solution...]]

Upvotes: 1

Paweł Fus
Paweł Fus

Reputation: 45079

It's caused by setting different pointPlacement for series. I suggest to use default setting for that option: http://jsfiddle.net/dfq4b6xz/1/

Upvotes: 2

Related Questions