Skip to content

Commit a1dec5a

Browse files
committed
1 parent 902cb76 commit a1dec5a

File tree

4 files changed

+201
-201
lines changed

4 files changed

+201
-201
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
node_modules
2-
dist
1+
node_modules
2+
dist
33
package-lock.json

package.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
{
2-
"version": "1.0.1",
3-
"scripts": {
4-
"build": "webpack --mode production",
5-
"start": "webpack-dev-server"
6-
},
7-
"license": "Custom",
8-
"private": true,
9-
"main": "./src/index.js",
10-
"devDependencies": {
11-
"copy-webpack-plugin": "^6.0.2",
12-
"html-webpack-plugin": "^3.2.0",
13-
"webpack-cli": "^3.3.10",
14-
"webpack-dev-server": "^3.9.0"
15-
},
16-
"dependencies": {
17-
"@arction/lcjs": "^3.2.0",
18-
"@arction/xydata": "^1.4.0",
19-
"clean-webpack-plugin": "^3.0.0",
20-
"webpack": "^4.41.2",
21-
"webpack-stream": "^5.2.1"
22-
}
23-
}
1+
{
2+
"version": "1.0.1",
3+
"scripts": {
4+
"build": "webpack --mode production",
5+
"start": "webpack-dev-server"
6+
},
7+
"license": "Custom",
8+
"private": true,
9+
"main": "./src/index.js",
10+
"devDependencies": {
11+
"copy-webpack-plugin": "^6.0.2",
12+
"html-webpack-plugin": "^3.2.0",
13+
"webpack-cli": "^3.3.10",
14+
"webpack-dev-server": "^3.9.0"
15+
},
16+
"dependencies": {
17+
"@arction/lcjs": "^3.2.0",
18+
"@arction/xydata": "^1.4.0",
19+
"clean-webpack-plugin": "^3.0.0",
20+
"webpack": "^4.41.2",
21+
"webpack-stream": "^5.2.1"
22+
}
23+
}

src/index.js

Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,99 @@
1-
/*
2-
* LightningChartJS example that showcases real-time OHLC-packing using a variant of OHLC-series.
3-
*/
4-
// Import LightningChartJS
5-
const lcjs = require('@arction/lcjs')
6-
7-
// Extract required parts from LightningChartJS.
8-
const {
9-
lightningChart,
10-
AxisTickStrategies,
11-
AxisScrollStrategies,
12-
OHLCSeriesTypes,
13-
emptyLine,
14-
Themes
15-
} = lcjs
16-
17-
// Import data-generator from 'xydata'-library.
18-
const {
19-
createProgressiveTraceGenerator
20-
} = require('@arction/xydata')
21-
22-
// Decide on an origin for DateTime axis ( cur time - 5 minutes ).
23-
const fiveMinutesInMs = 5 * 60 * 1000
24-
const dateOrigin = new Date(new Date().getTime() - fiveMinutesInMs)
25-
26-
// Create a XY Chart.
27-
const chart = lightningChart().ChartXY({
28-
// theme: Themes.darkGold
29-
})
30-
// Use DateTime X-axis using previously defined origin.
31-
chart
32-
.getDefaultAxisX()
33-
.setTickStrategy(
34-
AxisTickStrategies.DateTime,
35-
(tickStrategy) => tickStrategy.setDateOrigin(dateOrigin)
36-
)
37-
38-
// Set chart title and modify the padding of the chart.
39-
chart
40-
.setTitle('Realtime OHLC and line')
41-
.setPadding({
42-
right: 42
43-
})
44-
// Modify AutoCursor to only show TickMarker and Gridline over X Axis.
45-
chart.setAutoCursor(cursor => {
46-
cursor.disposeTickMarkerY()
47-
cursor.setGridStrokeYStyle(emptyLine)
48-
})
49-
50-
// Configure X-axis to be progressive.
51-
chart.getDefaultAxisX()
52-
.setScrollStrategy(AxisScrollStrategies.progressive)
53-
// View fits 5 minutes.
54-
.setInterval(0, fiveMinutesInMs)
55-
56-
// Show title 'USD' on Y axis.
57-
chart.getDefaultAxisY()
58-
.setTitle('USD')
59-
60-
// Add underlying line series.
61-
const lineSeries = chart.addLineSeries()
62-
.setCursorEnabled(false)
63-
.setStrokeStyle((strokeStyle) => strokeStyle
64-
.setFillStyle(fill => fill.setA(70))
65-
.setThickness(1)
66-
)
67-
68-
// Add OHLC series with automatic packing (so we can feed it XY-points just like for the line series).
69-
const ohlcSeriesAutoPacking = chart.addOHLCSeries(
70-
// Specify type of OHLC-series for adding points
71-
{ seriesConstructor: OHLCSeriesTypes.AutomaticPacking }
72-
)
73-
// Set packing resolution to 100 ms so we can zoom to full resolution.
74-
.setPackingResolution(100)
75-
76-
const add = (points) => {
77-
lineSeries.add(points)
78-
// With automatic packing, the add method accepts data points that use the {x, y} format (for example, {x: time, y: measurement}).
79-
// OHLC Series can automatically pack these raw measurements into OHLC data.
80-
ohlcSeriesAutoPacking.add(points)
81-
}
82-
83-
// Generate data using 'xydata'-library.
84-
createProgressiveTraceGenerator()
85-
.setNumberOfPoints(10000)
86-
.generate()
87-
.toPromise()
88-
.then((data) => data.map((p) => ({
89-
// Resolution = 100 ms.
90-
x: p.x * 100, y: p.y
91-
})))
92-
.then((data) => {
93-
// Add 5 minutes worth of points immediately ( to simulate previous data ).
94-
add(data.splice(0, Math.round(5 * 60 * 10)))
95-
// Then stream some more
96-
setInterval(() => {
97-
add(data.splice(0, 1))
98-
}, 50)
99-
})
1+
/*
2+
* LightningChartJS example that showcases real-time OHLC-packing using a variant of OHLC-series.
3+
*/
4+
// Import LightningChartJS
5+
const lcjs = require('@arction/lcjs')
6+
7+
// Extract required parts from LightningChartJS.
8+
const {
9+
lightningChart,
10+
AxisTickStrategies,
11+
AxisScrollStrategies,
12+
OHLCSeriesTypes,
13+
emptyLine,
14+
Themes
15+
} = lcjs
16+
17+
// Import data-generator from 'xydata'-library.
18+
const {
19+
createProgressiveTraceGenerator
20+
} = require('@arction/xydata')
21+
22+
// Decide on an origin for DateTime axis ( cur time - 5 minutes ).
23+
const fiveMinutesInMs = 5 * 60 * 1000
24+
const dateOrigin = new Date(new Date().getTime() - fiveMinutesInMs)
25+
26+
// Create a XY Chart.
27+
const chart = lightningChart().ChartXY({
28+
// theme: Themes.darkGold
29+
})
30+
// Use DateTime X-axis using previously defined origin.
31+
chart
32+
.getDefaultAxisX()
33+
.setTickStrategy(
34+
AxisTickStrategies.DateTime,
35+
(tickStrategy) => tickStrategy.setDateOrigin(dateOrigin)
36+
)
37+
38+
// Set chart title and modify the padding of the chart.
39+
chart
40+
.setTitle('Realtime OHLC and line')
41+
.setPadding({
42+
right: 42
43+
})
44+
// Modify AutoCursor to only show TickMarker and Gridline over X Axis.
45+
chart.setAutoCursor(cursor => {
46+
cursor.disposeTickMarkerY()
47+
cursor.setGridStrokeYStyle(emptyLine)
48+
})
49+
50+
// Configure X-axis to be progressive.
51+
chart.getDefaultAxisX()
52+
.setScrollStrategy(AxisScrollStrategies.progressive)
53+
// View fits 5 minutes.
54+
.setInterval(0, fiveMinutesInMs)
55+
56+
// Show title 'USD' on Y axis.
57+
chart.getDefaultAxisY()
58+
.setTitle('USD')
59+
60+
// Add underlying line series.
61+
const lineSeries = chart.addLineSeries()
62+
.setCursorEnabled(false)
63+
.setStrokeStyle((strokeStyle) => strokeStyle
64+
.setFillStyle(fill => fill.setA(70))
65+
.setThickness(1)
66+
)
67+
68+
// Add OHLC series with automatic packing (so we can feed it XY-points just like for the line series).
69+
const ohlcSeriesAutoPacking = chart.addOHLCSeries(
70+
// Specify type of OHLC-series for adding points
71+
{ seriesConstructor: OHLCSeriesTypes.AutomaticPacking }
72+
)
73+
// Set packing resolution to 100 ms so we can zoom to full resolution.
74+
.setPackingResolution(100)
75+
76+
const add = (points) => {
77+
lineSeries.add(points)
78+
// With automatic packing, the add method accepts data points that use the {x, y} format (for example, {x: time, y: measurement}).
79+
// OHLC Series can automatically pack these raw measurements into OHLC data.
80+
ohlcSeriesAutoPacking.add(points)
81+
}
82+
83+
// Generate data using 'xydata'-library.
84+
createProgressiveTraceGenerator()
85+
.setNumberOfPoints(10000)
86+
.generate()
87+
.toPromise()
88+
.then((data) => data.map((p) => ({
89+
// Resolution = 100 ms.
90+
x: p.x * 100, y: p.y
91+
})))
92+
.then((data) => {
93+
// Add 5 minutes worth of points immediately ( to simulate previous data ).
94+
add(data.splice(0, Math.round(5 * 60 * 10)))
95+
// Then stream some more
96+
setInterval(() => {
97+
add(data.splice(0, 1))
98+
}, 50)
99+
})

0 commit comments

Comments
 (0)