Aren Hovsepyan Aren Hovsepyan - 1 month ago 6
Javascript Question

How to draw a line through Y axis 0 value

I need to create a line to show that it is zero on Y axis if there are negative values.
I need this since I've disabled labels on the Y axis and want to show via a line that it is 0 and separate negative values from positive ones.

enter image description here

Answer

Draw the line using plotLines, setting the value to 0:

plotLines: [{
            color: '#000000',
            width: 1,
            value: 0
        }],

Here is a demo:

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: 'Column chart with negative values'
        },
        xAxis: {
            categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
        },
        credits: {
            enabled: false
        },
        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]
        }],
        yAxis:{
        gridLineWidth: 0,
        plotLines: [{
                color: '#000000',
                width: 1,
                value: 0
            }],
        labels: {
        enabled: false
        }
        }
    });
});
rect {
  stroke-width:0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

PS: the code for this bar chart is not mine, I copied it from Highcharts' website: http://www.highcharts.com/demo/column-negative