feat(web): K线图库对比 —— TradingView Lightweight Charts 实现 + 双库切换

- 按确认方案「两套实现并存对比」:
  - npm 依赖 lightweight-charts@4.2.3(v3 §21 推荐库)
  - components/StockChart/chartTypes.ts:共享 props 接口
  - CandleChart.tsx(ECharts 版,重构复用共享类型)+ CandleChartLW.tsx
    (Lightweight 版:蜡烛+成交量副刻度+MA+成交实心箭头/未成交信号圆点 markers)
  - StockChart.tsx wrapper;个股页顶部「ECharts / Lightweight」切换(默认 Lightweight)
- /stocks/600519.SH 冒烟 200;tsc --noEmit 通过
This commit is contained in:
Simon
2026-09-09 07:21:07 +08:00
parent 37510c1b89
commit 03fb463216
7 changed files with 218 additions and 21 deletions
@@ -8,7 +8,8 @@
* - signals(未成交意图):空心标记 —— signal_buy 红圈 ▲ / signal_sell 绿圈
* 组件只做展示,绝不自行计算(数据来自后端 Chart API)。
*
* 基于 ECharts candlestick;组件层隔离,便于后续替换 TradingView Lightweight Charts。
* 基于 ECharts candlestick(ECharts 实现);另一套实现见 CandleChartLW.tsx(TradingView
* Lightweight Charts),两套共用同一 props 接口(chartTypes.ts)供对比。
*/
import { useEffect, useRef } from "react";
import * as echarts from "echarts/core";
@@ -16,6 +17,8 @@ import { BarChart, CandlestickChart, LineChart, ScatterChart } from "echarts/cha
import { GridComponent, TooltipComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";
import type { ChartMarker } from "@/lib/types";
import type { CandleChartProps } from "./chartTypes";
export type { CandleDatum } from "./chartTypes";
echarts.use([
CandlestickChart,
@@ -38,31 +41,15 @@ const C = {
ma60: "#d4a72c",
};
export interface CandleDatum {
time: string;
open: number;
close: number;
low: number;
high: number;
}
export function CandleChart({
data,
volume,
volume = [],
indicators = {},
fills = [],
signals = [],
height = 480,
name = "",
}: {
data: CandleDatum[];
volume?: { time: string; value: number | null }[];
indicators?: Record<string, { time: string; value: number | null }[]>;
fills?: ChartMarker[];
signals?: ChartMarker[];
height?: number;
name?: string;
}) {
}: CandleChartProps) {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {