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

Tooltip should guess best datetime format #568

Closed
eolsson opened this Issue Nov 14, 2011 · 5 comments

Comments

Projects
None yet
3 participants
@eolsson
Contributor

eolsson commented Nov 14, 2011

  1. Create a chart with datetime axis spanning several days
  2. Notice that the tooltip format and axis label format are the same
  3. Zoom in to 'hour' level

Result: The tooltip still displays the day but the axis shows hours
Expected: That they are the same unless user overrides the behaviour.

Example: http://jsfiddle.net/5eKLE/
Forum thread: http://highslide.com/forum/viewtopic.php?f=9&t=13296

@TorsteinHonsi

This comment has been minimized.

Collaborator

TorsteinHonsi commented Nov 14, 2011

Axes ticks are spread out based on tickPixelInterval or tickInterval, so we can't expect them to math the tooltip points one by one. While points can be at random positions, x axis ticks will be drawn at regular intervals.

However, in Highstock, the tooltip header format uses an intelligent guess for the best interval based on the lowest distance between points. See http://jsfiddle.net/highcharts/5eKLE/1/. This could be implemented in Highcharts as well

@TorsteinHonsi

This comment has been minimized.

Collaborator

TorsteinHonsi commented May 11, 2012

Demo with the fix applied: http://jsfiddle.net/highcharts/5eKLE/2/

The fix can also be backported to Highcharts 2.2: http://jsfiddle.net/highcharts/5eKLE/3/

@algiecas

This comment has been minimized.

algiecas commented Apr 10, 2013

When there's only one data point in chart and xDateFormat is not set, the tooltip shows unformatted date, i.e. in milliseconds. That's because xAxis.closestPointRange is undefined.

Is this an expected behavior? How should I work around this issue?

I can't figure out anything else but fixing it by defaulting to one of the date formats in such case... Is there a better solution?

// Guess the best date format based on the closest point distance (#568)
if (isDateTime && !xDateFormat) {

    if (xAxis.closestPointRange) {
        for (n in timeUnits) {
            if (timeUnits[n] >= xAxis.closestPointRange) {
                xDateFormat = tooltipOptions.dateTimeLabelFormats[n];
                break;
            }
        }
    }
    else {
        xDateFormat = tooltipOptions.dateTimeLabelFormats.day;
    }
}
@TorsteinHonsi

This comment has been minimized.

Collaborator

TorsteinHonsi commented Apr 11, 2013

Seems like a perfectly valid solution to the problem, I'll commit a variation of it.

@algiecas

This comment has been minimized.

algiecas commented Apr 11, 2013

Hi again.

I think your change introduced a bug for pie charts (when xAxis is not available).

It throws error when hovering on pie saying that you cannot read closestPointRange from xAxis.

TorsteinHonsi added a commit that referenced this issue Apr 11, 2013

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