简体   繁体   English

Highcharts负对数刻度解决方案停止工作

[英]Highcharts negative logarithmic scale solution stopped working

I generate graph code for a graph with a logarithmic scale with negative values.我为带有负值的对数刻度生成图形代码。 The result is in the fiddle below.结果在下面的小提琴中。

I made the function required to handle the negative values like here and it worked perfectly.我制作了 function 来处理像这里这样的负值,它工作得很好。 But since some days it does not function anymore.但是从某些日子开始,它不再是 function 了。 So I adjusted the code according to this article but it still does not work.所以我根据这篇文章调整了代码,但还是不行。 See my JSFidddle :见我的JSFiddle

(function (H) {
    H.addEvent(H.Axis, 'afterInit', function () {
        const logarithmic = this.logarithmic;

        if (logarithmic && this.options.custom.allowNegativeLog) {

            // Avoid errors on negative numbers on a log axis
            this.positiveValuesOnly = false;

            // Override the converter functions
            logarithmic.log2lin = num => {
                const isNegative = num < 0;

                let adjustedNum = Math.abs(num);

                if (adjustedNum < 10) {
                    adjustedNum += (10 - adjustedNum) / 10;
                }

                const result = Math.log(adjustedNum) / Math.LN10;
                return isNegative ? -result : result;
            };

            logarithmic.lin2log = num => {
                const isNegative = num < 0;

                let result = Math.pow(10, Math.abs(num));
                if (result < 10) {
                    result = (10 * (result - 1)) / (10 - 1);
                }
                return isNegative ? -result : result;
            };
        }
    });
}(Highcharts));

I get an error 10 but the examples in that description don't go anywhere.我收到错误 10,但该描述中的示例在任何地方都没有 go。

What is going on and how do I repair?发生了什么事,我该如何修复?

Apparently Highcharts made a change to the Axis definition.显然 Highcharts 对轴定义进行了更改。 The Y-axis was defined as: Y 轴定义为:

yAxis:
{
  type: 'logarithmic',
  allowNegativeLog: true,
  title:
  {
    text: 'Regen Spreiding ( mm)'
  },
  min: 0.0,
  max: 25.40
},

And it is now required to be (at least it is working with this modification):现在需要它(至少它正在使用此修改):

  type: 'logarithmic',
  custom:
  {
    allowNegativeLog: true,
  },

NOTE: this is together with the modified function H which now starts with:注意:这与修改后的 function H 一起,现在以:

H.addEvent(H.Axis, 'afterInit', function () {

If you landed here like I did, checkout this JSFiddle by Highcharts with working demo.如果您像我一样来到这里,请查看Highcharts的 JSFiddle 和工作演示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM