HansR
Posts: 62
Joined: Fri Jan 01, 2021 9:44 am
Location: NL
Contact: Website

softMax does not seem to work properly

Hi,

I have a function which creates a chart and adds data dynamically. It is supposed to plot rain and rain speed. See code below.

The both Y-axis have a minimum of 0 and a softMax of 1. However, the Y-axis does not seems to go below 6 while I would expect it to go from 0-1 when there are no data to show and then adjust as required.

Why does the Y-axis not go from 0 to 1 but has the minimal MAX value if 6 (beyond which it does scale up OK) ?

Code: Select all

    function doRegen() {
        chart = Highcharts.StockChart('chartcontainer', {
            credits: {
                enabled: true
            },
            xAxis: {
                type: 'datetime',
                crosshair: true,
                ordinal: false,
                dateTimeLabelFormats: {
                    day: '%e %b',
                    week: '%e %b %y',
                    month: '%b %y',
                    year: '%Y'
                }
            },
            yAxis: {
                id: 'Rain',
                title: {
                    text: 'Regen (mm)'
                },
                opposite: false,
                softMax: 1,
                min: 0,
                allowDecimals: false,
                labels: {
                    align: 'right',
                    x: -5,
                    y: -2
                }
            },
            legend: {
                enabled: true
            },
            plotOptions: {
                series: {
                    states: {
                        hover: {
                            halo: {
                                size: 5,
                                opacity: 0.25
                            }
                        }
                    },
                    marker: {
                        enabled: false,
                        states: {
                            hover: {
                                enabled: true,
                                radius: 0.1
                            }
                        }
                    }
                },
            },
            tooltip: {
                shared: true,
                split: true,
                valueDecimals: 1,
                xDateFormat: '%A, %b %e, %H:%M'
            },
            series: [],
            rangeSelector: {
                buttons: [{
                    count: 18,
                    type: 'hour',
                    text: '18h'
                }, {
                    count: 36,
                    type: 'hour',
                    text: '36h'
                }, {
                    type: 'all',
                    text: 'All'
                }],
                inputEnabled: false
            }
        });
        chart.showLoading();
        chart.setTitle({
            text: 'Regen and Regensnelheid'
        });
        chart.addAxis({
            id: 'Rrate',
            title: {
                text: 'Regensnelheid (mm/hr)'
            },
            opposite: true,
            softMax: 1,
            min: 0,
            allowDecimals: false,
            labels: {
                align: 'left',
                x: 5,
                y: -2
            }
        }, false, false);
        Promise.all([]).then(() => {
            RegenAddSeries(chart);
            chart.hideLoading();
            chart.redraw();
        });
    }
HansR
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: softMax does not seem to work properly

Hi HansR,

Thanks for contacting us with your question.

In case of softMax property the data is essential so please create a live demo with hardcoded data showing the issue. You can start here: https://jsfiddle.net/BlackLabel/9qbkwv0m//

Regards!
Mateusz Bernacik
Highcharts Developer
HansR
Posts: 62
Joined: Fri Jan 01, 2021 9:44 am
Location: NL
Contact: Website

Re: softMax does not seem to work properly

mateusz.b wrote: Fri Apr 08, 2022 10:36 am Hi HansR,

Thanks for contacting us with your question.

In case of softMax property the data is essential so please create a live demo with hardcoded data showing the issue. You can start here: https://jsfiddle.net/BlackLabel/9qbkwv0m//

Regards!
Hi Mateusz,

I created a fiddle here : https://jsfiddle.net/HansR/v3xahp75/19/ but it does not show the axis which I do not understand. This is how I use it, only the dynamic loading of the data is left out. And normally there would be more points but this is representative of the situation.
How to continue?

Regards, Hans
HansR
HansR
Posts: 62
Joined: Fri Jan 01, 2021 9:44 am
Location: NL
Contact: Website

Re: softMax does not seem to work properly

I added my defaults to make it exactly as used and based the fiddle: https://jsfiddle.net/HansR/v3xahp75/
HansR
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: softMax does not seem to work properly

Hi HansR,

Thanks for the demo.

I've checked it but I couldn't find anything incorrect. If I missed something, please let me know.

It seems that chart have three Y axes (check console https://jsfiddle.net/BlackLabel/j0vfwnL8/):
- first one with softMax = 1, two series and max equal to 1, where max is determined by softMax because series data have lower values
- second one with one series, max value ~ 0.385, without softMax property, where max value is determined by series data because softMax is not set
- third one without series and with undefined max value, with softMax property set to 1. In this case max value is undefined because no series is assigned to the axis.

Let me know what would you like to change.

Regards!
Mateusz Bernacik
Highcharts Developer
HansR
Posts: 62
Joined: Fri Jan 01, 2021 9:44 am
Location: NL
Contact: Website

Re: softMax does not seem to work properly

Hi, sorry I come back to this so late.

I do not seem to understand it:

1) How can I see the axis in the console? I don't know how to handle the console.
2) How can I see the same in my own runtime environment (should this be in the javascript debugger)?
3) If I look at the code I add only two axis both of which have one series and each have their own soft max.

So how come you see three axis and even one axis with two series?
I am seriously missing the point here which may be the cause of problem.

Regards,
Hans
HansR
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: softMax does not seem to work properly

Hi HansR,

In the jsFiddle that I provided in my previous post, there is a console.log method at the end of the file, that outputs message in the console. Shortcut to open console might vary depending on your browser and system so to learn that please google it out. The the mentioned console.log method show in console all chart's axes using chart reference (console.log(chart.yAxis)). That way you can inspect axis object (its configuration) and learn about set options like softMax.

There are three axes, because one comes from chart config, second one you add with chart.addAxis method and third belongs to the navigator. I mentioned third, navigator axis in my previous post but it can be ignored as it is most likely irrelevant in this case.

Let me know for which series and axis you want to set softMax and I will help with the config.

Regards!
Mateusz Bernacik
Highcharts Developer
HansR
Posts: 62
Joined: Fri Jan 01, 2021 9:44 am
Location: NL
Contact: Website

Re: softMax does not seem to work properly

OK... it is beginning to dawn but I am not there yet.

I did put the console.log for the y-axis in my operational charts and there (with the same code) the y-axis from the config gets a max=7 (the max from the add-axis has a max=0.5 value) and the value for the navigator also has a max=7 value. (I look at the values in the console of Chrome).
(if you wish I can give you the link where to look at it)

The rain axis addition occurs with me in two charts (one is replicated in the jsfiddle) both get a value 7 for the max y-axis value while the series has 0.

Do I assume correctly that the 7 is a default when no max or softMax is supplied? If that is not true, where does the 7 in my operational code come from? Where does max gets its value from? Apparently the dataseries - with a max value much less than 0.5 - is overruled here. How?

In operational situation the chart is created as follows and the question is where does the 7 come from.

This part is what is in the jsfiddle:

Code: Select all

doRegen() which defines the chart and the first axis with softMax: 1
                              calling chart.AddAxis() with softMax: 1 for the second chart
                              calling RegenAddSeries(chart) to add the series which have been prepared as arrays elsewhere

The RegenAddSeries function is the only deviation from the jsfiddle and goes like:

Code: Select all

function RegenAddSeries(thisChart) {
           thisChart.addSeries({
            name: 'Regenval',
            id: 'RainFall',
            data: RainFall,        // (which is a:     var RainFall = []; )
            fillOpacity: '0.2',
            color: 'green',
            yAxis: 'Rain',
            type: 'area',
            lineWidth: 2,
            zIndex: 5,
            tooltip: {
                valueSuffix: ' mm'
            }
        }, false);
HansR
HansR
Posts: 62
Joined: Fri Jan 01, 2021 9:44 am
Location: NL
Contact: Website

Re: softMax does not seem to work properly

NOTE: with the Chrome debugger I can get to the point of the dataseries reading and there the max values are undefined or null. After reading the dataseries the max value becomes 7. All y-values are < 1.

Filling the array goes like:

Code: Select all

    function raindataAjax() {
        RainFall.length = 0;
        RainRate.length = 0;
        return $.ajax({
            url: 'raindata.json',
            cache: false,
            datatype: 'json'
        }).fail(function (xhr, textStatus, errorThrown) {
            console.log('raindata.json ' + textStatus + ' : ' + errorThrown);
        }).done(function (resp) {
            for (var i = 0; i < resp.rfall.length; i++) RainFall.push([resp.rfall[i][0], resp.rfall[i][1]]);
            for (var i = 0; i < resp.rrate.length; i++) RainRate.push([resp.rrate[i][0], resp.rrate[i][1]]);
        })
    }

HansR
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: softMax does not seem to work properly

Hi HansR,

Axis' extremes by default are calculated based on series data. If in your case max data value is less than 0.5 then it is highly unlikely for y axis to have max equal to 7. To tell what is the cause I need to take look at the code. Please same as before create a live demo with the issue: https://jsfiddle.net/BlackLabel/9qbkwv0m//

Regards!
Mateusz Bernacik
Highcharts Developer
HansR
Posts: 62
Joined: Fri Jan 01, 2021 9:44 am
Location: NL
Contact: Website

Re: softMax does not seem to work properly

Hi Mateusz,

Yes, I know the idea is the Axis' extremes are calculated is calculated by the data extremes, my problem is that something causes this not to work properly.

So, I created a jsfiddle (https://jsfiddle.net/HansR/v3xahp75/) which is an exact copy of how it runs operationally. This means it is a pretty large fiddle (sorry for that) but I'll explain the basic working below (which is rather simple), and below that I will describe my issues with this.

How does it work:
There are several charts in this fiddle. In my environment this is the content of one file which is loaded on request by the user through the little drop down menu.
  1. First part of the code is the theme as implemented in my system
  2. Choose rain (because that is where the problem is).
  3. This causes the function DoRegen() to be executed - follow the flow;
  4. This causes 1) the chart to be defined; 2) the Loading mess to be displayed; 3) The Title to be set and then the Axis to be added. NOTE that one axis is defined in the chart definition, the other is added later
  5. Then in a Promise.All construct it adds the series.
  6. The RegenAddSeries() function assigns the data arrays to the chart.
The data array's are filled in the initialisation through the ajax function. Check out the raindataAjax() to see how it goes.
Unfortunately, probably because of CORS, these functions are in error (see console).
So I need a json function which works with jsfiddle.

My problem:
Anyway, when I get this to work, you will see that the rain data have zero (0) for all dates but the axis softMax / max value is set to 7.
I am beginning to fear there is an interaction between the charts.

I will look for a way to have all json's read by the jsfiddle.

Cheers,
HansR
HansR
HansR
Posts: 62
Joined: Fri Jan 01, 2021 9:44 am
Location: NL
Contact: Website

Re: softMax does not seem to work properly

Hi Mateusz,

For some reason I cannot get myjson.com to work.
jsonserve.com I can get to accept my smallest json, but it does not read in the jsfiddle and larger json's (my data go up to 428K in one json) are not accepted.

If I understand things well, the way to simulate the async reading of data I have to use /echo/json but that implies I have to enter all data literally as data below the URL in the ajax calls. That would make the jsfiddle really unreadable.

So I entered only three values for the raindataAjax() and the true values for GraphconfigAjax() . It is not a 100% reproduction of the operational situation but it seems good enough

Initially you see nothing but if you select 'Regen' (Dutch for Rain) you will see the problem: the Y-axis gets a max value of 4 (it should be one as the softMax is 1 and the max value in the series is 0.0). This is not the number 7 which happens in the operational situation but it is a similar reproduction of the issue.

Could you explain why I get a value of 4 on the Y-axis? https://jsfiddle.net/HansR/v3xahp75/

Regards,
HansR
HansR
Posts: 62
Joined: Fri Jan 01, 2021 9:44 am
Location: NL
Contact: Website

Re: softMax does not seem to work properly

OK, I finally gave all charts some values and the problem occurs identical to the initial chart (Overzicht / Overview) and Regen / Rain)

Regards,
HansR
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: softMax does not seem to work properly

Hi HansR,

Just want to let you know that the case and demo is quite complex so it takes a bit longer than usually to process all those informations. Nevertheless I am working on the solution and I will be back with an answer asap. Thanks for your detailed explanation, thanks to that I was able to reproduce the issue!

Regards!
Mateusz Bernacik
Highcharts Developer
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: softMax does not seem to work properly

HansR,

Please try to add endOnTick: false property to axes config in doRegen() function.
Demo: https://jsfiddle.net/BlackLabel/juxbc4h0/
API reference: https://api.highcharts.com/highcharts/yAxis.endOnTick

Let me know if it helped.
Regards!
Mateusz Bernacik
Highcharts Developer

Return to “Highcharts Stock”