-
Notifications
You must be signed in to change notification settings - Fork 0
/
demoNice.js
64 lines (51 loc) · 1.8 KB
/
demoNice.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import {jmcharts as c} from '../../src/index'
import * as dh from './DataHelper'
const r = c.renderer
const w = c.widget
const s = c.series
const data = dh.generateOHLCV(50000)
const root = c.root('chart')
.width(600)
.height(500)
root.append(w.label())
.text('JMCharts demo - SnakeOilCoin prices')
.class('jmc-header-2')
.height(25)
.paddingBottom(10)
const ohlcChart = root.append(w.chart()).height(300)
const ohlcSeries = s.ohlcSeries(data.time, data.open, data.high, data.low, data.close)
ohlcChart.appendRenderer(r.ohlc(ohlcSeries))
.color('blue')
.addContextValueSupplier()
.addTooltipSupplier(i => dh.getOHLCTooltip(ohlcSeries, i))
const movingAvg1 = dh.movingAverage(s.series(data.time, data.close), 5).name('MA5')
ohlcChart.appendRenderer(r.line(movingAvg1))
.color('red')
.addContextValueSupplier()
const movingAvg2 = dh.movingAverage(s.series(data.time, data.close), 20).name('MA20')
ohlcChart.appendRenderer(r.line(movingAvg2))
.color('grey')
.addContextValueSupplier()
const crossingUp = dh.crossingUp(movingAvg1, movingAvg2, data.low)
ohlcChart.appendRenderer(r.shape(crossingUp))
.color('#999')
.shape(r.shapes.equilateralTriangleUp(20))
.fill(true)
.addTooltipSupplier(i => `<h2>Buy SnakeOil here!</h2>`)
const crossingDown = dh.crossingDown(movingAvg1, movingAvg2, data.high)
ohlcChart.appendRenderer(r.shape(crossingDown))
.color('#999')
.shape(r.shapes.equilateralTriangleDown(20))
.fill(true)
.addTooltipSupplier(i => `<h2>Sell SnakeOil here!</h2>`)
root.append(w.chart())
.height(100)
.appendRenderer(r.bar(s.series(data.time, data.vol).name('vol')))
.addContextValueSupplier()
root.append(w.dateAxis())
root.append(w.controlPanel())
root.append(w.profiler().height(15))
root.append(w.currentValues().height(15))
root.append(w.tooltip())
root.init()
root.update()