问题描述
我为带有对数刻度且值为负的图形生成图形代码。结果在下面的小提琴中。
我制作了处理诸如here之类的负值所需的函数,并且运行良好。但是由于某些日子,它不再起作用了。因此,我根据this article调整了代码,但仍然无法正常工作。请参阅我的JSFidddle:
(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));
我得到一个错误10,但that description中的示例却一无所获。
这是怎么回事,我该如何修理?
解决方法
显然Highcharts对Axis定义进行了更改。 Y轴定义为:
yAxis:
{
type: 'logarithmic',allowNegativeLog: true,title:
{
text: 'Regen Spreiding ( mm)'
},min: 0.0,max: 25.40
},
现在需要(至少正在使用此修改):
type: 'logarithmic',custom:
{
allowNegativeLog: true,},
注意:这与修改后的函数H一起使用,该函数现在以:
开头H.addEvent(H.Axis,'afterInit',function () {