Highcharts:显示指数值的y轴

xu3bshqb  于 2022-11-10  发布在  Highcharts
关注(0)|答案(1)|浏览(221)

以下是我的代码示例:

const chart = Highcharts.stockChart('container', {
    rangeSelector: {
        selected: 1,
        inputBoxStyle: {
            right: '80px'
        }
    },
    yAxis: [{
        type: 'logarithmic',
        tickPositioner: function () {        
        let lowestValue = this.dataMin;
        let highestValue = this.dataMax;

        if((highestValue - lowestValue) < 5 ) {
            lowestValue = this.dataMin;
            highestValue = this.dataMax;
        } else {
            lowestValue = Math.floor((this.dataMin));
            highestValue = Math.ceil((this.dataMax));
        }

        let numberOfTicks = 5;
        let positions = [];

        // first and last point are always present
        if(this.isLog) {
            positions.push(Math.log(lowestValue) / Math.log(10));
        } else {
            positions.push(lowestValue);
        }

        for(let i = 1; i < numberOfTicks; i++) {
            let eachPosition = lowestValue + (((highestValue - lowestValue)/numberOfTicks) * i);

            if(this.isLog) {
                let eachPositionAsLog = Math.log(eachPosition) / Math.log(10);

                positions.push(eachPositionAsLog);
            } else {
                // limit max decimal places to just 2
                // There is a bug with most browsers rounding of 1.005. Workaround is to add 0.00001
                eachPosition = Math.round((eachPosition + 0.00001) * 100) / 100;
                positions.push(eachPosition);
            }
        }

        // first and last point are always present
        if(this.isLog) {
            positions.push(Math.log(highestValue) / Math.log(10));
        } else {
            positions.push(highestValue);
        } 
        console.log( positions )
        return positions;
    }
    }],
    series: [{
        name: 'USD to EUR',
        data: usdeur
    }],

    exporting: {
        chartOptions: {
            chart: {
                width: 1024,
                height: 768
            }
        }
    }
});

document.getElementById('button').addEventListener('click', () => {
    chart.exportChart();
});

***这是我在jsFiddle中的代码块:***https://jsfiddle.net/Subhabrata/h59e7qc1/12/
我想要的输出应该是:

我正在使用Highcharts/Highstock版本10. 1. 0。请有人帮我解决问题。我无法找出问题所在。
经过我的分析,我发现。它在highstockidojs内部的某个地方坏了,自定义的滴答定位器正在填充正确的点,但它没有填充在标签中。

sqserrrh

sqserrrh1#

属性isLog不再可用。请改用属性logarithmic,该属性在对数打开时不会为空。
解决方法:
替换this.isLog =〉this.logarithmic
我修好了你的小提琴。看看这里
https://jsfiddle.net/jvinjamoori/mh5s8Ln1/

相关问题