Dygraph.js - 当 x 为日期时获取图形的中心点
Dygraph.js - Get center point of graph when x is Date
如何在实际缩放尺寸的动态图中获得中心 point/data?
当x轴为整数时很容易,但是当x轴为日期类型(Unix时间戳)时如何做到这一点?
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.
所以你应该可以这样做:
var range = g.xAxisRange();
var midPointMs = 0.5 * (range[0] + range[1]);
var midPointDate = new Date(midPointMs);
如何在实际缩放尺寸的动态图中获得中心 point/data?
当x轴为整数时很容易,但是当x轴为日期类型(Unix时间戳)时如何做到这一点?
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.
所以你应该可以这样做:
var range = g.xAxisRange();
var midPointMs = 0.5 * (range[0] + range[1]);
var midPointDate = new Date(midPointMs);