diff --git a/src/components/kline-chart.tsx b/src/components/kline-chart.tsx index 0d7ab16..b9542a0 100644 --- a/src/components/kline-chart.tsx +++ b/src/components/kline-chart.tsx @@ -53,8 +53,8 @@ const GRID = "#e4e4e7"; const MARKER = "#f59e0b"; // MA / 指标线配色 -const MA_COLORS = ["#f59e0b", "#3b82f6", "#a855f7", "#10b981"]; -const MA_PERIODS = [5, 10, 20, 30]; +const MA_COLORS = ["#f59e0b", "#3b82f6", "#a855f7"]; +const MA_PERIODS = [5, 10, 20]; const MACD_DIF = "#3b82f6"; const MACD_DEA = "#f59e0b"; const RSI_COLOR = "#a855f7"; @@ -331,12 +331,37 @@ export function KLineChart({ data, mode, hasAddedDate, indicators }: Props) { chart.timeScale().fitContent(); } + // 颜色图例:根据启用的指标生成 + const legend: { color: string; label: string }[] = []; + if (indicators.ma) { + MA_PERIODS.forEach((p, i) => legend.push({ color: MA_COLORS[i % MA_COLORS.length], label: `MA${p}` })); + } + if (indicators.macd) { + legend.push({ color: MACD_DIF, label: "DIF" }, { color: MACD_DEA, label: "DEA" }); + } + if (indicators.rsi) legend.push({ color: RSI_COLOR, label: "RSI14" }); + if (indicators.kdj) { + legend.push({ color: KDJ_K, label: "K" }, { color: KDJ_D, label: "D" }, { color: KDJ_J, label: "J" }); + } + return ( -
+