如何在LightningChart JS医疗仪表板实现多通道差异化采样率?
LightningChart JS医疗仪表板多通道差异化采样率实现方案
要实现ECG/心率(256样本/秒)、呼吸率(128样本/秒)的差异化采样率,核心是放弃全局采样率配置,为每个通道单独指定采样率参数,而非依赖全局默认值。以下是具体实现步骤和代码示例:
1. 通道创建时单独指定采样率
调用dashboard.createChannel()创建每个通道时,显式传入sampleRate参数,覆盖全局配置(若存在)。
// 初始化医疗仪表板(无需设置全局sampleRate) const dashboard = lightningChart().MedicalDashboard({ container: 'dashboard-container' // 移除全局sampleRate配置,或保留但通道创建时覆盖 }) // 创建ECG通道(256样本/秒) const ecgChannel = dashboard.createChannel({ type: 'ECG', name: 'ECG', sampleRate: 256, lowerLimit: -0.5, upperLimit: 2.5 }) // 创建心率通道(256样本/秒) const heartRateChannel = dashboard.createChannel({ type: 'HR', name: 'Heart Rate', sampleRate: 256, lowerLimit: 40, upperLimit: 180 }) // 创建呼吸率通道(128样本/秒) const respirationChannel = dashboard.createChannel({ type: 'RESP', name: 'Respiration', sampleRate: 128, lowerLimit: 0, upperLimit: 30 }) // 创建NIBP通道(按需配置,通常为间断性数据) const nibpChannel = dashboard.createChannel({ type: 'NIBP', name: 'NIBP' })
2. 按对应采样率推送数据
每个通道的数据推送频率需匹配其采样率,同时必须使用**时间戳(timestamp)**确保多通道时间轴同步。
// ECG数据推送(每3.90625ms一次,对应256样本/秒) setInterval(() => { const timestamp = Date.now() // 替换为实际ECG数据生成逻辑 const ecgValue = Math.random() * 3 - 0.5 ecgChannel.addSample({ timestamp, value: ecgValue }) }, 1000 / 256) // 呼吸率数据推送(每7.8125ms一次,对应128样本/秒) setInterval(() => { const timestamp = Date.now() // 替换为实际呼吸率数据生成逻辑 const respValue = Math.sin(Date.now() / 1000) * 15 + 15 respirationChannel.addSample({ timestamp, value: respValue }) }, 1000 / 128) // 心率数据推送(同ECG采样率) setInterval(() => { const timestamp = Date.now() // 替换为实际心率数据生成逻辑 const hrValue = Math.random() * 140 + 40 heartRateChannel.addSample({ timestamp, value: hrValue }) }, 1000 / 256) // NIBP数据推送(间断性,比如每5秒一次) setInterval(() => { const timestamp = Date.now() nibpChannel.addSample({ timestamp, systolic: Math.random() * 40 + 100, diastolic: Math.random() * 30 + 60, mean: Math.random() * 35 + 75 }) }, 5000)
关键注意事项
- 不要依赖全局
sampleRate配置:全局值仅作为通道未指定时的默认值,修改全局值会覆盖所有未单独设置的通道采样率,这就是你之前所有通道变成128样本/秒的原因。 - 必须使用时间戳推送数据:所有通道的样本都要携带毫秒级
timestamp,LightningChart会自动基于时间戳对齐多通道时间轴,避免采样率不同导致的时间偏移。 - 采样率与推送频率匹配:确保数据推送的时间间隔严格对应采样率(1000ms / 采样率),否则会出现数据密度异常。
内容的提问来源于stack exchange,提问作者Anish Arya
相关产品推荐
相关产品推荐

