Vis.js 关注当前时间(红线)
Vis.js focus on the Current Time (Red Line)
如何更改 Vis.js 时间线,使其始终关注当前时间线(红线),以便我知道时间线中现在正在发生什么。根据我有多远或缩放级别,时间轴应该向左或向右平移并关注当前时间行情。
我在这里考虑两个选项:要么有一个 setInterval() 运行 每 15 分钟更新一次并关注当前时间,要么在页面上有一个手动执行此操作的按钮。
根据我的研究,到目前为止,我发现它与一个按钮相关联,但显然还不起作用:
document.getElementById('focusNow').onclick = function() {
timeline.focus(timeline.currentTime.bar)
};
我知道这是一个老问题,但我是这样解决的:
var refresh = 10000;
timeline = new vis.Timeline(container, data, options);
function updateTimeline(refresh) {
setTimeout(function(){
var current = new Date();
timeline.moveTo(current);
updateTimeline(refresh)
}, refresh);
}
updateTimeline(refresh);
updateTimeline 函数每 10 秒运行一次并移动时间线以使当前时间居中(使用 moveTo() 函数),从而使红线保持居中。一旦我的项目完成,我将更新 github link.
如何更改 Vis.js 时间线,使其始终关注当前时间线(红线),以便我知道时间线中现在正在发生什么。根据我有多远或缩放级别,时间轴应该向左或向右平移并关注当前时间行情。
我在这里考虑两个选项:要么有一个 setInterval() 运行 每 15 分钟更新一次并关注当前时间,要么在页面上有一个手动执行此操作的按钮。
根据我的研究,到目前为止,我发现它与一个按钮相关联,但显然还不起作用:
document.getElementById('focusNow').onclick = function() {
timeline.focus(timeline.currentTime.bar)
};
我知道这是一个老问题,但我是这样解决的:
var refresh = 10000;
timeline = new vis.Timeline(container, data, options);
function updateTimeline(refresh) {
setTimeout(function(){
var current = new Date();
timeline.moveTo(current);
updateTimeline(refresh)
}, refresh);
}
updateTimeline(refresh);
updateTimeline 函数每 10 秒运行一次并移动时间线以使当前时间居中(使用 moveTo() 函数),从而使红线保持居中。一旦我的项目完成,我将更新 github link.