snuuve
snuuve

Reputation: 315

Dygraph.js - Get center point of graph when x is Date

How to get center point/data in dygraphs in actual zoom size?

It's easy when x axis is integer, but how to do this when x axis is Date type(Unix timestamps)?

Upvotes: 0

Views: 136

Answers (1)

danvk
danvk

Reputation: 16905

The docs for xAxisRange say:

Returns the currently-visible x-range. This can be affected by zooming, panning or a call to updateOptions. Returns a two-element array: [left, right]. If the Dygraph has dates on the x-axis, these will be millis since epoch.

So you should be able to do something like:

var range = g.xAxisRange();
var midPointMs = 0.5 * (range[0] + range[1]);
var midPointDate = new Date(midPointMs);

Upvotes: 1

Related Questions