Highcharts - Grid line height

2019-08-23 07:10发布

I want the grid lines of highchart to appear only till 75% of the chart height and rest of the chart should not show the grid lines. Is there a way to set the height of grid line?

xAxis: {               
    gridLineWidth: 1,               
    gridLineDashStyle: 'longdash',
    gridLineColor: '#B3BABB',
}

标签: highcharts
1条回答
再贱就再见
2楼-- · 2019-08-23 07:20

In general, it is not supported, but simple change will allow you that: http://jsfiddle.net/ngk6vtbh/

(function(H) {
    H.wrap(H.Tick.prototype, 'render', function(p, index, old, opacity) {
        var tick = this,
            d,
            size = 0.25; // = 75%, 0.5 = 50%, 0.75 = 25% etc.
        p.call(this, index, old, opacity);

        if(tick.gridLine && this.axis.isXAxis) {

            d = tick.gridLine.d.split(' '); // get default path

            d[2] = ( d[5] - d[2] ) * size + tick.axis.chart.plotTop; // modify path - don't forget about plotTop

            tick.gridLine.attr({
                d: d // apply new path
            });
        }

    });
})(Highcharts)
查看更多
登录 后发表回答