highcharts 如何得到 Y轴上的最大值


举个例子

或者直接看这个吧

表中的曲线的最大值是12.4,但是我不知道y轴上的最大值15是怎么计算出来,有了最大值当然就能得到刻度了.因为暂时没有时间阅读源代码所以求问.(处女问啊).

highcharts JavaScript

Surufel 10 years, 6 months ago

http://code.highcharts.com/highcharts.src.js
实际上应该是先算刻度再去设置最大值的


 /** line 586
 * Take an interval and normalize it to multiples of 1, 2, 2.5 and 5
 * @param {Number} interval
 * @param {Array} multiples
 * @param {Number} magnitude
 * @param {Object} options
 */
function normalizeTickInterval(interval, multiples, magnitude, options)
    var normalized, i;

    // round to a tenfold of 1, 2, 2.5 or 5
    magnitude = pick(magnitude, 1);
    normalized = interval / magnitude;

    // multiples for a linear scale
    if (!multiples) {
        multiples = [1, 2, 2.5, 5, 10];

        // the allowDecimals option
        if (options && options.allowDecimals === false) {
            if (magnitude === 1) {
                multiples = [1, 2, 5, 10];
            } else if (magnitude <= 0.1) {
                multiples = [1 / magnitude];
            }
        }
    }

    // normalize the interval to the nearest multiple
    for (i = 0; i < multiples.length; i++) {
        interval = multiples[i];
        if (normalized <= (multiples[i] + (multiples[i + 1] || multiples[i])) / 2) {
            break;
        }
    }

    // multiply back to the correct magnitude
    interval *= magnitude;

    return interval;
}



 /** line 7687
 * Set the max ticks of either the x and y axis collection
 */
setMaxTicks: function () {

    var chart = this.chart,
        maxTicks = chart.maxTicks || {},
        tickPositions = this.tickPositions,
        key = this._maxTicksKey = [this.xOrY, this.pos, this.len].join('-');

    if (!this.isLinked && !this.isDatetimeAxis && tickPositions && tickPositions.length > (maxTicks[key] || 0) && this.options.alignTicks !== false) {
        maxTicks[key] = tickPositions.length;
    }
    chart.maxTicks = maxTicks;
},

传说D一日君 answered 10 years, 6 months ago

Your Answer