|
1 | | -/* |
2 | | - * LightningChartJS example that showcases the 'packing resolution' property of StockSeries. |
3 | | - */ |
4 | | -// Import LightningChartJS |
5 | | -const lcjs = require('@arction/lcjs') |
6 | | - |
7 | | -// Extract required parts from LightningChartJS. |
8 | | -const { |
9 | | - lightningChart, |
10 | | - AxisTickStrategies, |
11 | | - OHLCSeriesTypes, |
12 | | - emptyLine, |
13 | | - Themes |
14 | | -} = lcjs |
15 | | - |
16 | | -// Import data-generator from 'xydata'-library. |
17 | | -const { |
18 | | - createProgressiveTraceGenerator |
19 | | -} = require('@arction/xydata') |
20 | | - |
21 | | -const dataSpan = 60 * 60 * 1000 |
22 | | -const dataFrequency = 1 * 1000 |
23 | | - |
24 | | -// Decide on an origin for DateTime axis. |
25 | | -const dateOrigin = new Date(2018, 0, 1) |
26 | | -// Create charts and series for two different packing resolutions. |
27 | | -const dashboard = lightningChart().Dashboard({numberOfColumns: 1, numberOfRows: 2}) |
28 | | -const chartDefault = dashboard.createChartXY({ |
29 | | - columnIndex: 0, |
30 | | - rowIndex: 0, |
31 | | - // theme: Themes.darkGold |
32 | | -}) |
33 | | -// Use DateTime TickStrategy with custom origin date. |
34 | | -chartDefault |
35 | | - .getDefaultAxisX() |
36 | | - .setTickStrategy( |
37 | | - AxisTickStrategies.DateTime, |
38 | | - (tickStrategy) => tickStrategy.setDateOrigin(dateOrigin) |
39 | | - ) |
40 | | - |
41 | | -chartDefault |
42 | | - .setTitle('Default packing resolution') |
43 | | - .setAutoCursor(cursor => { |
44 | | - cursor.disposeTickMarkerY() |
45 | | - cursor.setGridStrokeYStyle(emptyLine) |
46 | | - }) |
47 | | -// Preventing ResultTable from getting cut at the edge |
48 | | -chartDefault.setPadding({ |
49 | | - right: 42 |
50 | | -}) |
51 | | - |
52 | | -// show title 'USD on Y axis |
53 | | -chartDefault.getDefaultAxisY() |
54 | | - .setTitle('USD') |
55 | | - |
56 | | -const chartLow = dashboard.createChartXY({ |
57 | | - columnIndex: 0, |
58 | | - rowIndex: 1, |
59 | | - // theme: Themes.darkGold |
60 | | -}) |
61 | | -// Use DateTime TickStrategy with custom origin date. |
62 | | -chartLow |
63 | | - .getDefaultAxisX() |
64 | | - .setTickStrategy( |
65 | | - AxisTickStrategies.DateTime, |
66 | | - (tickStrategy) => tickStrategy.setDateOrigin(dateOrigin) |
67 | | - ) |
68 | | - |
69 | | -chartLow |
70 | | - .setTitle('Very small packing resolution') |
71 | | - .setAutoCursor(cursor => { |
72 | | - cursor.disposeTickMarkerY() |
73 | | - cursor.setGridStrokeYStyle(emptyLine) |
74 | | - }) |
75 | | -// Preventing ResultTable from getting cut at the edge |
76 | | -chartLow.setPadding({ |
77 | | - right: 42 |
78 | | -}) |
79 | | - |
80 | | -// show title 'USD on Y axis |
81 | | -chartLow.getDefaultAxisY() |
82 | | - .setTitle('USD') |
83 | | - |
84 | | -const seriesDefault = chartDefault.addOHLCSeries( |
85 | | - // Specify type of OHLC-series for adding points |
86 | | - { seriesConstructor: OHLCSeriesTypes.AutomaticPacking } |
87 | | -) |
88 | | - .setName('Default packing resolution') |
89 | | - |
90 | | -const seriesLow = chartLow.addOHLCSeries({ seriesConstructor: OHLCSeriesTypes.AutomaticPacking }) |
91 | | - .setName('Very small packing resolution') |
92 | | - // Set packing resolution that is equal to the minimum resolution between two points. |
93 | | - // (essentially allows users to zoom to full resolution) |
94 | | - .setPackingResolution(dataFrequency) |
95 | | - |
96 | | -// Push points to both series. |
97 | | -createProgressiveTraceGenerator() |
98 | | - .setNumberOfPoints(dataSpan / dataFrequency) |
99 | | - .generate() |
100 | | - .toPromise() |
101 | | - .then((data) => data.map((p) => ({ |
102 | | - x: p.x * dataFrequency, y: p.y |
103 | | - }))) |
104 | | - .then((data) => { |
105 | | - seriesDefault.add(data) |
106 | | - seriesLow.add(data) |
107 | | - // Fit axes to fully show difference between packing resolutions. (without fitting |
108 | | - // the initial pixel size of axes would drastically affect automatic packing resolution) |
109 | | - chartDefault.getDefaultAxisX().fit() |
110 | | - chartLow.getDefaultAxisX().fit() |
111 | | - }) |
| 1 | +/* |
| 2 | + * LightningChartJS example that showcases the 'packing resolution' property of StockSeries. |
| 3 | + */ |
| 4 | +// Import LightningChartJS |
| 5 | +const lcjs = require('@arction/lcjs') |
| 6 | + |
| 7 | +// Extract required parts from LightningChartJS. |
| 8 | +const { |
| 9 | + lightningChart, |
| 10 | + AxisTickStrategies, |
| 11 | + OHLCSeriesTypes, |
| 12 | + emptyLine, |
| 13 | + Themes |
| 14 | +} = lcjs |
| 15 | + |
| 16 | +// Import data-generator from 'xydata'-library. |
| 17 | +const { |
| 18 | + createProgressiveTraceGenerator |
| 19 | +} = require('@arction/xydata') |
| 20 | + |
| 21 | +const dataSpan = 60 * 60 * 1000 |
| 22 | +const dataFrequency = 1 * 1000 |
| 23 | + |
| 24 | +// Decide on an origin for DateTime axis. |
| 25 | +const dateOrigin = new Date(2018, 0, 1) |
| 26 | +// Create charts and series for two different packing resolutions. |
| 27 | +const dashboard = lightningChart().Dashboard({numberOfColumns: 1, numberOfRows: 2}) |
| 28 | +const chartDefault = dashboard.createChartXY({ |
| 29 | + columnIndex: 0, |
| 30 | + rowIndex: 0, |
| 31 | + // theme: Themes.darkGold |
| 32 | +}) |
| 33 | +// Use DateTime TickStrategy with custom origin date. |
| 34 | +chartDefault |
| 35 | + .getDefaultAxisX() |
| 36 | + .setTickStrategy( |
| 37 | + AxisTickStrategies.DateTime, |
| 38 | + (tickStrategy) => tickStrategy.setDateOrigin(dateOrigin) |
| 39 | + ) |
| 40 | + |
| 41 | +chartDefault |
| 42 | + .setTitle('Default packing resolution') |
| 43 | + .setAutoCursor(cursor => { |
| 44 | + cursor.disposeTickMarkerY() |
| 45 | + cursor.setGridStrokeYStyle(emptyLine) |
| 46 | + }) |
| 47 | +// Preventing ResultTable from getting cut at the edge |
| 48 | +chartDefault.setPadding({ |
| 49 | + right: 42 |
| 50 | +}) |
| 51 | + |
| 52 | +// show title 'USD on Y axis |
| 53 | +chartDefault.getDefaultAxisY() |
| 54 | + .setTitle('USD') |
| 55 | + |
| 56 | +const chartLow = dashboard.createChartXY({ |
| 57 | + columnIndex: 0, |
| 58 | + rowIndex: 1, |
| 59 | + // theme: Themes.darkGold |
| 60 | +}) |
| 61 | +// Use DateTime TickStrategy with custom origin date. |
| 62 | +chartLow |
| 63 | + .getDefaultAxisX() |
| 64 | + .setTickStrategy( |
| 65 | + AxisTickStrategies.DateTime, |
| 66 | + (tickStrategy) => tickStrategy.setDateOrigin(dateOrigin) |
| 67 | + ) |
| 68 | + |
| 69 | +chartLow |
| 70 | + .setTitle('Very small packing resolution') |
| 71 | + .setAutoCursor(cursor => { |
| 72 | + cursor.disposeTickMarkerY() |
| 73 | + cursor.setGridStrokeYStyle(emptyLine) |
| 74 | + }) |
| 75 | +// Preventing ResultTable from getting cut at the edge |
| 76 | +chartLow.setPadding({ |
| 77 | + right: 42 |
| 78 | +}) |
| 79 | + |
| 80 | +// show title 'USD on Y axis |
| 81 | +chartLow.getDefaultAxisY() |
| 82 | + .setTitle('USD') |
| 83 | + |
| 84 | +const seriesDefault = chartDefault.addOHLCSeries( |
| 85 | + // Specify type of OHLC-series for adding points |
| 86 | + { seriesConstructor: OHLCSeriesTypes.AutomaticPacking } |
| 87 | +) |
| 88 | + .setName('Default packing resolution') |
| 89 | + |
| 90 | +const seriesLow = chartLow.addOHLCSeries({ seriesConstructor: OHLCSeriesTypes.AutomaticPacking }) |
| 91 | + .setName('Very small packing resolution') |
| 92 | + // Set packing resolution that is equal to the minimum resolution between two points. |
| 93 | + // (essentially allows users to zoom to full resolution) |
| 94 | + .setPackingResolution(dataFrequency) |
| 95 | + |
| 96 | +// Push points to both series. |
| 97 | +createProgressiveTraceGenerator() |
| 98 | + .setNumberOfPoints(dataSpan / dataFrequency) |
| 99 | + .generate() |
| 100 | + .toPromise() |
| 101 | + .then((data) => data.map((p) => ({ |
| 102 | + x: p.x * dataFrequency, y: p.y |
| 103 | + }))) |
| 104 | + .then((data) => { |
| 105 | + seriesDefault.add(data) |
| 106 | + seriesLow.add(data) |
| 107 | + // Fit axes to fully show difference between packing resolutions. (without fitting |
| 108 | + // the initial pixel size of axes would drastically affect automatic packing resolution) |
| 109 | + chartDefault.getDefaultAxisX().fit() |
| 110 | + chartLow.getDefaultAxisX().fit() |
| 111 | + }) |
0 commit comments