javascript - Dygraph.js - 当 x 为日期时获取图表的中心点

标签 javascript dygraphs

如何在实际缩放尺寸下获取dygraphs中的中心点/数据?

当x轴是整数时很容易,但是当x轴是Date类型(Unix时间戳)时怎么办?

最佳答案

docs for xAxisRange说:

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);

关于javascript - Dygraph.js - 当 x 为日期时获取图表的中心点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36452543/

相关文章:

reactjs - 如何正确缩放页面上的 Dygraph?

javascript - 在 React 中发出自定义事件

javascript - 为什么函数在全局对象中不可用?

javascript - 如何解构一个ES6模块联合导出

graph - 测绘仪 : how to clear the graph data and reload it?

javascript - 在 Dygraph 的 Y 轴标签中添加逗号分隔符

javascript - 当屏幕出现时调用哪个生命周期事件?

javascript - 如何在 https 站点上通过 http 加载 css 文件。

javascript - 当我在平移时更新dygraph时,如何使dygraph不丢失其y轴?

javascript - dygraphs 中的 y 轴超过 2 个