feat: 动态加载全部27个KLineChart内置指标

This commit is contained in:
2026-09-09 21:10:20 +08:00
parent e66dd36bef
commit e45e96743e
2 changed files with 19 additions and 17 deletions
+18 -10
View File
@@ -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)