|
4 | 4 | // Import LightningChartJS |
5 | 5 | const lcjs = require('@lightningchart/lcjs') |
6 | 6 |
|
7 | | -// Import xydata |
8 | | -const xydata = require('@lightningchart/xydata') |
9 | | - |
10 | 7 | // Extract required parts from LightningChartJS. |
11 | 8 | const { lightningChart, AxisScrollStrategies, emptyFill, Themes } = lcjs |
12 | 9 |
|
13 | | -// Import data-generators from 'xydata'-library. |
14 | | -const { createSampledDataGenerator } = xydata |
15 | | - |
16 | 10 | // Create a XY Chart. |
17 | 11 | const chart = lightningChart({ |
18 | 12 | resourcesBaseUrl: new URL(document.head.baseURI).origin + new URL(document.head.baseURI).pathname + 'resources/', |
@@ -1632,16 +1626,21 @@ const point = [ |
1632 | 1626 | { x: 1586, y: 94 }, |
1633 | 1627 | { x: 1587, y: 82 }, |
1634 | 1628 | ] |
1635 | | -// Create a data generator to supply a continuous stream of data. |
1636 | | -createSampledDataGenerator(point, 1, 10) |
1637 | | - .setSamplingFrequency(1) |
1638 | | - .setInputData(point) |
1639 | | - .generate() |
1640 | | - .setStreamBatchSize(48) |
1641 | | - .setStreamInterval(50) |
1642 | | - .setStreamRepeat(true) |
1643 | | - .toStream() |
1644 | | - .forEach((point) => { |
1645 | | - // Push the created points to the series. |
1646 | | - series.appendSample({ x: point.timestamp, y: point.data.y }) |
| 1629 | + |
| 1630 | +let i = 0 |
| 1631 | +let prev = performance.now() |
| 1632 | +const stream = () => { |
| 1633 | + const now = performance.now() |
| 1634 | + const delta = Math.min(now - prev, 1000) |
| 1635 | + prev = now |
| 1636 | + const pCount = Math.round((1000 * delta) / 1000) |
| 1637 | + const points = new Array(pCount).fill(0).map((_, ii) => { |
| 1638 | + const sample = point[(i + ii) % point.length] |
| 1639 | + sample.x = i + ii |
| 1640 | + return sample |
1647 | 1641 | }) |
| 1642 | + i += pCount |
| 1643 | + series.appendJSON(points) |
| 1644 | + requestAnimationFrame(stream) |
| 1645 | +} |
| 1646 | +stream() |
0 commit comments