将 html5 视频与 highchart.js 折线图同步

发布于 2025-01-09 00:48:32 字数 200 浏览 0 评论 0原文

我有一个一分钟长的火车移动视频和一些关于他的位置、车载加速度计等的数据系列。

我的目标是制作那些随视频动态绘制的测量值的折线图(使用 Highcharts.js)每秒 20 点。图表必须随视频移动,这样,如果用户返回,图表也会在同一帧上移动,依此类推。

我想知道是否有一种方法可以将事件附加到视频进度条并每 x 毫秒和/或每次用户播放/停止视频时重新绘制图表

I have a one minute long video of a train moving and some data series about his position, onboard accelerometer etc.

My goal is to make line charts (with Highcharts.js) of those measurements that are dynamically drawn with the video at a rate of 20points per second. The charts have to move with the video, so that if the user go back also the charts go at the same frame and so on.

I was wondering if there's a way to attach an event to the video progress bar and redraw the chart every x milliseconds and/or every time that the user play/stop the video

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相权↑美人 2025-01-16 00:48:32

将视频元素的 timeupdate 事件与 Highcharts 系列的 setData 方法连接起来就足够了。

示例:

let currentDataIndex = 0;
const video = document.getElementById("video1");

const chart = Highcharts.chart('container', {
    series: [{
        // Highcharts mutate original data array, so use a copy
        data: data[currentDataIndex].slice()
    }]
});

const updateChartData = index => {
    chart.series[0].setData(data[index].slice());
    currentDataIndex = index;
};

video.addEventListener('timeupdate', e => {
    const second = Math.floor(video.currentTime);

    if (second !== currentDataIndex) {
        updateChartData(second);
    }
});

现场演示: http://jsfiddle.net/BlackLabel/8a6yvjs5/< /a>

API 参考: https://api.highcharts.com/class-reference/Highcharts.Series#setData

文档:

https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/currentTime

https://developer.mozilla.org/en-US/docs/ Web/API/HTMLMediaElement/timeupdate_event

Connecting timeupdate event for a video element with setData method for a Highcharts series should be enough.

Example:

let currentDataIndex = 0;
const video = document.getElementById("video1");

const chart = Highcharts.chart('container', {
    series: [{
        // Highcharts mutate original data array, so use a copy
        data: data[currentDataIndex].slice()
    }]
});

const updateChartData = index => {
    chart.series[0].setData(data[index].slice());
    currentDataIndex = index;
};

video.addEventListener('timeupdate', e => {
    const second = Math.floor(video.currentTime);

    if (second !== currentDataIndex) {
        updateChartData(second);
    }
});

Live demo: http://jsfiddle.net/BlackLabel/8a6yvjs5/

API Reference: https://api.highcharts.com/class-reference/Highcharts.Series#setData

Docs:

https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/currentTime

https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/timeupdate_event

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文