New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting of date/times in Highstock changed? #5302

Closed
NickThissen opened this Issue May 10, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@NickThissen

NickThissen commented May 10, 2016

I have been using Highstock for some time for a graph with a date/time x-axis. I use a custom tooltip formatter that outputs the day name and time of day for each datapoint, alongside some other data included in the data.

It seems that the update from version 2.1.10 to version 4.2.0 broke the date formatting or at least it is not working for me anymore.

When I force my code to load the old version 2.1.10 it works again. Of course I would like to use the new version but I cannot find this change in the changelogs, and I cannot figure out what I should change to make it work again.

I am using the following code for the tooltip formatter:

        tooltip: {
            formatter: function() {
                var week = '?';
                var s = [];

                $.each(this.points, function(i, p) {
                    if (week === '?') week = p.point.week;
                    s.push('<span style="color:' + p.series.color + '">\u25CF</span> ' + p.series.name + ': ' + p.y);
                });

                // Create date from x point and format it 
                var date = new Date(this.x);
                var dateString = Highcharts.dateFormat('%a', date) + ' W' + week + ', ' + Highcharts.dateFormat('%H:%M', date);
                return dateString + '<br />' + s.join('<br />');
            },
            shared: true
        },

Expected behaviour

The code used to output correctly the name of the day in the "%a" formatter and the time of day in the "%H:%M" formatter.

Actual behaviour

The date formatter outputs nothing at all, just a blank string.

Live demo of the issue

Using script version 2.1.10 the date formatter outputs the time:
http://jsfiddle.net/2wu79psd/

Remove the specific version from the script src tag (to get latest version) and it outputs nothing:
http://jsfiddle.net/sa9tzn0k/

Code is exactly the same, only difference is the version of Highstock used.

@pawelfus

This comment has been minimized.

Contributor

pawelfus commented May 10, 2016

As I remember, dateFormat() always required number as second param, not Date object (API). Maybe there was a coincidence, that Date used to work here?

Anyway, fixed demo: http://jsfiddle.net/sa9tzn0k/1/

So in your case:

 var dateString = Highcharts.dateFormat('%a', this.x) + ' W' + week + ', ' + Highcharts.dateFormat('%H:%M', this.x);

 return dateString + '<br />' + s.join('<br />');
@NickThissen

This comment has been minimized.

NickThissen commented May 10, 2016

Huh, that was easy... thanks. Must have been a coincidence then indeed!

For some reason I thought 'this.x' was returning a string as it showed it as a string in the Chrome console. But perhaps Chrome is being too clever and automatically formatting it?

@pawelfus

This comment has been minimized.

Contributor

pawelfus commented May 10, 2016

this.x for a datetime axis should always be a number (timestamp). I don't think Chrome has anything to do with it.

@TorsteinHonsi

This comment has been minimized.

Collaborator

TorsteinHonsi commented May 10, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment