feat: 动态加载全部27个KLineChart内置指标
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { dispose, init } from 'klinecharts'
|
||||
import { dispose, init, getSupportedIndicators } from 'klinecharts'
|
||||
|
||||
const MINUTE = 60 * 1000
|
||||
const LOAD_BAR_COUNT = 500
|
||||
@@ -14,13 +14,13 @@ const PERIODS = [
|
||||
{ key: '1d', period: { span: 1, type: 'day' }, candleType: 'candle_solid' }
|
||||
]
|
||||
|
||||
const INDICATORS = [
|
||||
{ key: 'MA', name: 'MA', stacked: true },
|
||||
{ key: 'BOLL', name: 'BOLL', stacked: true },
|
||||
{ key: 'MACD', name: 'MACD', stacked: false },
|
||||
{ key: 'RSI', name: 'RSI', stacked: false },
|
||||
{ key: 'VOL', name: 'VOL', stacked: false }
|
||||
]
|
||||
const PRICE_OVERLAY_INDICATORS = new Set(['MA', 'EMA', 'BOLL', 'SMA', 'BBI', 'SAR'])
|
||||
|
||||
const INDICATORS = getSupportedIndicators().map(name => ({
|
||||
key: name,
|
||||
name,
|
||||
stacked: PRICE_OVERLAY_INDICATORS.has(name)
|
||||
}))
|
||||
|
||||
let chart = null
|
||||
let rawBars = null
|
||||
@@ -552,8 +552,16 @@ function bindToolbar() {
|
||||
document.querySelectorAll('#period-switcher button').forEach((btn) => {
|
||||
btn.addEventListener('click', () => switchPeriod(btn.dataset.period))
|
||||
})
|
||||
document.querySelectorAll('#indicator-switcher button').forEach((btn) => {
|
||||
btn.addEventListener('click', () => toggleIndicator(btn.dataset.indicator))
|
||||
|
||||
const indicatorContainer = document.getElementById('indicator-switcher')
|
||||
INDICATORS.forEach(ind => {
|
||||
const btn = document.createElement('button')
|
||||
btn.type = 'button'
|
||||
btn.dataset.indicator = ind.key
|
||||
btn.textContent = ind.key
|
||||
btn.className = 'toolbar-btn'
|
||||
btn.addEventListener('click', () => toggleIndicator(ind.key))
|
||||
indicatorContainer.appendChild(btn)
|
||||
})
|
||||
document.getElementById('zoom-in').addEventListener('click', doZoomIn)
|
||||
document.getElementById('zoom-out').addEventListener('click', doZoomOut)
|
||||
|
||||
Reference in New Issue
Block a user