Close Editor Run Reset Auto Update CJS const lcjs = require('@lightningchart/lcjs')
const { lightningChart, Themes, PalettedFill, DataSet, ColorRGBA, LUT, PointSeriesTypes3D, AxisScrollStrategies, AxisTickStrategies } = lcjs
const channelCount = 5
const dataRate = 1000
const timeView = 15000
const lc = lightningChart()
const chart = lc
.Chart3D({
// theme: Themes.darkGold,
})
.setTitle(``)
.setBoundingBox({ x: 1, y: 0.5, z: 1 })
chart.axisZ
.setScrollStrategy(AxisScrollStrategies.scrolling)
.setDefaultInterval((state) => ({
start: state.dataMax ?? 0,
end: (state.dataMax ?? 0) - timeView,
stopAxisAfter: false,
}))
.setTickStrategy(AxisTickStrategies.Time)
const dataSet = new DataSet({
schema: {
z: { pattern: 'progressive' },
...Object.fromEntries(new Array(channelCount).fill(0).map((_, i) => [`x${i}`, { pattern: null }])),
...Object.fromEntries(new Array(channelCount).fill(0).map((_, i) => [`y${i}`, { pattern: null }])),
},
}).setMaxSampleCount(Math.ceil((timeView * dataRate) / 1000))
const channels = new Array(channelCount).fill(0).map((_, i) => {
const series = chart
.addPointSeries({
type: PointSeriesTypes3D.Pixelated,
schema: {
x: { pattern: null },
y: { pattern: null },
z: { pattern: 'progressive' },
},
})
.setDataSet(dataSet, { x: `x${i}`, y: `y${i}`, z: 'z' })
.setPointStyle((points) => points.setSize(2))
return { series, prevX: Math.random() * 10, prevY: Math.random() * 10 }
})
let tPrev = performance.now()
const streamData = () => {
const now = performance.now()
const delta = Math.min(now - tPrev, 1000)
tPrev = now
const pCount = Math.round((dataRate * delta) / 1000)
const zStep = dataRate / 1000
const zFirst = channels[0].series.getNextSampleIndex() * zStep
const points = new Array(pCount).fill(0).map((_, ii) => {
return {
z: zFirst + ii * zStep,
...Object.fromEntries(
channels.map((ch, i) => {
const next = ch.prevX + Math.random() * 2 - 1
ch.prevX = next
return [`x${i}`, next]
}),
),
...Object.fromEntries(
channels.map((ch, i) => {
const next = ch.prevY + Math.random() * 2 - 1
ch.prevY = next
return [`y${i}`, next]
}),
),
}
})
dataSet.appendJSON(points)
requestAnimationFrame(streamData)
}
streamData()
Multi-channel 3D Real-time Scatter - Editor Example of real-time data feeding and automatic data cleaning in a multi-channel 3D real-time scatter chart use case
3D point series work exactly same as XY variants. You can configure maximum sample count to keep in memory, and then stream large amounts of high rate data in.