如果是负数据,如何在第0个y轴刻度标签旁边绘制x轴?

时间:2017-10-16 07:11:05

标签: highcharts

我想在负数据的情况下在第0个y轴刻度标签旁边绘制x轴。参考图片:To plot Xaxis next to 0th tick label 有没有办法在Highcharts中实现这个目标?

1 个答案:

答案 0 :(得分:0)

请参阅此实时工作演示http://jsfiddle.net/kkulig/gxxtfn67/

我稍微修改了 xAxis过零插件https://github.com/ppoliani/xAxis-zero-crossing)的代码。我启用了y轴的渲染并删除了负责定位x轴标签的线。最终代码如下所示:

(function (H) {
    H.wrap(H.Axis.prototype, 'render', function (proceed) {

        var chart = this.chart,
            xAxis, yAxis, extremes, crossing;

        if (typeof this.options.zeroCrossing === 'boolean') {
            xAxis = chart['xAxis'][0];
            yAxis = chart['yAxis'][0];
            extremes = yAxis.getExtremes();
            crossing = Math.abs(extremes.min) + Math.abs(extremes.max);
            this.offset = yAxis.toPixels(crossing, true);
            chart.axisOffset[this.side] = 10;

        }
        proceed.call(this);

    });

}(Highcharts));

<强>更新

bar 系列的实时工作演示(倒置图表):http://jsfiddle.net/kkulig/gyp8n9ou/