HighCharts:2轴所有相同的值看起来都很奇怪

时间:2017-03-01 06:29:28

标签: javascript jquery highcharts

我目前正在使用当前版本的HighCharts并遇到问题,我有一个包含2轴(1列和1个样条曲线)的图形,但每个数据点的值完全相同:

我为这个问题创建了一个JSFiddle:http://jsfiddle.net/p8y5bqd3/

源代码也在这里:

/*** Experimental Highcharts plugin to implement chart.alignThreshold option. This primary axis will be computed first, then all following axes will be aligned to the threshold.Author: Torstein Hønsi Last revision: 2016-11-02 */
(function (H) {
var Axis = H.Axis,
    inArray = H.inArray,
    wrap = H.wrap;

wrap(Axis.prototype, 'adjustTickAmount', function (proceed) {
    var chart = this.chart,
        primaryAxis = chart[this.coll][0],
        primaryThreshold,
        primaryIndex,
        index,
        newTickPos,
        threshold;

    // Find the index and return boolean result
    function isAligned(axis) {
        index = inArray(threshold, axis.tickPositions); // used in while-loop
        return axis.tickPositions.length === axis.tickAmount && index === primaryIndex;
    }

    if (chart.options.chart.alignThresholds && this !== primaryAxis) {
        primaryThreshold = (primaryAxis.series[0] && primaryAxis.series[0].options.threshold) || 0;
        threshold = (this.series[0] && this.series[0].options.threshold) || 0;

        primaryIndex = primaryAxis.tickPositions && inArray(primaryThreshold, primaryAxis.tickPositions);

        if (this.tickPositions && this.tickPositions.length &&
                primaryIndex > 0 &&
                primaryIndex < primaryAxis.tickPositions.length - 1 &&
                this.tickAmount) {

            // Add tick positions to the top or bottom in order to align the threshold
            // to the primary axis threshold
            while (!isAligned(this)) {

                if (index < primaryIndex) {
                    newTickPos = this.tickPositions[0] - this.tickInterval;
                    this.tickPositions.unshift(newTickPos);
                    this.min = newTickPos;
                } else {
                    newTickPos = this.tickPositions[this.tickPositions.length - 1] + this.tickInterval;
                    this.tickPositions.push(newTickPos);
                    this.max = newTickPos;
                }
                proceed.call(this);
            }
        }

    } else {
        proceed.call(this);
    }
});
}(Highcharts));

 Highcharts.chart('container', {
chart: {
    alignThresholds: true,
    type: 'area'
},
title: {
    text: 'The <em>alignThreshold</em> option is true'
},
xAxis: {
    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: [{
    title: {
        text: 'Primary Axis'
    },
    gridLineWidth: 0
}, {
    title: {
        text: 'Secondary Axis'
    },
    opposite: true
}],
series: [{
type : 'column',
    data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    yAxis: 0,
    pointWidth: 20,

}, {
type : 'spline',
    data: [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000],
    yAxis: 1
}]
});

如果我使用第二轴的区域(或列,...)图表,一切正常。只有样条曲线或折线图才会出现此问题。

完美的解决方案应该在这张图片中看起来像(第一个数据点当然应该与所有其他数据点处于同一水平,但仍然超过1轴的0点) enter image description here

有没有办法为样条曲线或折线图定义偏移量,以便在辅助轴上线不从0开始?

0 个答案:

没有答案