kline-charts-react 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,7 +47,7 @@ pnpm add kline-charts-react
47
47
  ### Peer Dependencies
48
48
 
49
49
  ```bash
50
- npm install react react-dom
50
+ npm install react react-dom echarts
51
51
  ```
52
52
 
53
53
  ## 快速开始
@@ -128,13 +128,16 @@ function App() {
128
128
  import { KLineChart, type KLineDataProvider } from 'kline-charts-react';
129
129
 
130
130
  const customProvider: KLineDataProvider = {
131
+ // K 线数据(必须实现)
131
132
  getKline: async (params, signal) => {
132
- const res = await fetch(`/api/kline?symbol=${params.symbol}`, { signal });
133
- return res.json();
133
+ // params: { symbol, market, period, adjust }
134
+ const res = await fetch(`/api/kline?symbol=${params.symbol}&period=${params.period}`, { signal });
135
+ return res.json(); // 返回 KlineData[]
134
136
  },
137
+ // 分时数据(可选,仅分时模式使用)
135
138
  getTimeline: async (params, signal) => {
136
139
  const res = await fetch(`/api/timeline?symbol=${params.symbol}`, { signal });
137
- return res.json();
140
+ return res.json(); // 返回 TimelineData[]
138
141
  },
139
142
  };
140
143
 
@@ -144,6 +147,42 @@ const customProvider: KLineDataProvider = {
144
147
  />
145
148
  ```
146
149
 
150
+ #### KlineData 数据结构
151
+
152
+ `getKline` 需要返回 `KlineData[]`,每条数据的字段如下:
153
+
154
+ ```ts
155
+ interface KlineData {
156
+ date: string; // 日期/时间,如 "2024-01-15" 或 "2024-01-15 09:35"
157
+ open: number | null; // 开盘价
158
+ close: number | null; // 收盘价
159
+ high: number | null; // 最高价
160
+ low: number | null; // 最低价
161
+ volume: number | null; // 成交量
162
+ amount: number | null; // 成交额
163
+ changePercent?: number; // 涨跌幅(可选)
164
+ change?: number; // 涨跌额(可选)
165
+ amplitude?: number; // 振幅(可选)
166
+ turnoverRate?: number; // 换手率(可选)
167
+ }
168
+ ```
169
+
170
+ #### TimelineData 数据结构
171
+
172
+ `getTimeline` 需要返回 `TimelineData[]`,用于分时图展示:
173
+
174
+ ```ts
175
+ interface TimelineData {
176
+ time: string; // 时间,如 "09:30"
177
+ price: number; // 当前价格
178
+ volume: number; // 累计成交量
179
+ amount: number; // 累计成交额
180
+ avgPrice: number; // 均价
181
+ }
182
+ ```
183
+
184
+ > 技术指标(MA、MACD、KDJ 等)会由组件自动根据 K 线数据计算,无需在数据源中提供。
185
+
147
186
  ### 使用 Ref 控制图表
148
187
 
149
188
  ```tsx
@@ -335,25 +374,28 @@ export default {
335
374
  ```
336
375
  kline-charts-react/
337
376
  ├── src/
338
- │ ├── components/ # 子组件
339
- │ │ ├── Loading/
340
- │ │ ├── PeriodSelector/
341
- │ │ ├── IndicatorSelector/
342
- │ │ ├── Toolbar/
343
- │ │ └── MADisplay/
344
- ├── hooks/ # React Hooks
345
- ├── useKlineData.ts
346
- │ │ ├── useEcharts.ts
347
- │ │ └── useZoomHistory.ts
348
- ├── utils/ # 工具函数
349
- ├── indicators.ts
350
- │ │ ├── optionBuilder.ts
351
- │ │ └── timelineBuilder.ts
352
- │ ├── types/ # 类型定义
353
- │ ├── KLineChart.tsx # 主组件
354
- │ └── index.ts # 入口
355
- ├── playground/ # 调试环境
356
- └── dist/ # 构建产物
377
+ │ ├── components/ # 子组件
378
+ │ │ ├── Loading/ # 加载状态
379
+ │ │ ├── PeriodSelector/ # 周期切换
380
+ │ │ ├── IndicatorSelector/# 指标选择器
381
+ │ │ ├── Toolbar/ # 工具栏
382
+ │ │ ├── IndicatorDisplay/ # 主图指标数值
383
+ │ └── SubPaneTitle/ # 副图标题
384
+ │ ├── hooks/ # React Hooks
385
+ │ │ ├── useKlineData.ts # 数据获取 & 指标计算
386
+ │ │ ├── useEcharts.ts # ECharts 实例管理
387
+ │ └── useZoomHistory.ts # 缩放历史
388
+ │ ├── utils/ # 工具函数
389
+ │ │ ├── indicators.ts # 技术指标计算
390
+ │ │ ├── optionBuilder.ts # K 线 ECharts 配置
391
+ ├── timelineBuilder.ts# 分时图 ECharts 配置
392
+ ├── formatters.ts # 数据格式化
393
+ └── cache.ts # 数据缓存
394
+ ├── types/ # 类型定义
395
+ │ ├── KLineChart.tsx # 主组件
396
+ │ └── index.ts # 入口
397
+ ├── playground/ # 调试环境
398
+ └── dist/ # 构建产物
357
399
  ```
358
400
 
359
401
  ## 开发
@@ -1,12 +1,13 @@
1
- import { KlineWithIndicators, IndicatorType } from '../../types';
1
+ import { KlineWithIndicators, IndicatorType, ThemeConfig } from '../../types';
2
2
  interface IndicatorDisplayProps {
3
3
  data: KlineWithIndicators[];
4
4
  indicators: IndicatorType[];
5
5
  hoverIndex?: number | null;
6
+ theme: ThemeConfig;
6
7
  }
7
8
  /**
8
9
  * 主图指标数值显示组件
9
10
  * 支持 MA、BOLL、SAR、KC 指标
10
11
  */
11
- export declare function IndicatorDisplay({ data, indicators, hoverIndex }: IndicatorDisplayProps): import("react/jsx-runtime").JSX.Element | null;
12
+ export declare function IndicatorDisplay({ data, indicators, hoverIndex, theme }: IndicatorDisplayProps): import("react/jsx-runtime").JSX.Element | null;
12
13
  export {};