-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
274 lines (250 loc) · 7.45 KB
/
Copy pathindex.html
File metadata and controls
274 lines (250 loc) · 7.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FenshiChart - JavaScript分时图表库</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #0e1117;
color: #eee;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
header {
margin-bottom: 30px;
text-align: center;
}
h1 {
font-size: 32px;
margin-bottom: 5px;
}
.subtitle {
color: #888;
font-size: 18px;
}
.chart-container {
background-color: #0e1117;
border: 1px solid #222;
border-radius: 3px;
padding: 10px;
margin-bottom: 30px;
}
.controls {
display: flex;
gap: 10px;
margin: 20px 0;
}
button {
background-color: #1a1a1a;
color: #eee;
border: 1px solid #333;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
button:hover {
background-color: #333;
}
.section {
margin-bottom: 40px;
}
h2 {
border-bottom: 1px solid #333;
padding-bottom: 10px;
margin-bottom: 20px;
}
.demo-links {
display: flex;
gap: 20px;
margin-top: 30px;
}
.demo-link {
background-color: #1a1a1a;
border: 1px solid #333;
border-radius: 5px;
padding: 15px;
flex: 1;
text-decoration: none;
color: #eee;
transition: all 0.2s;
}
.demo-link:hover {
background-color: #333;
transform: translateY(-3px);
}
.demo-link h3 {
margin-top: 0;
color: #4896ff;
}
.demo-link p {
color: #888;
margin-bottom: 0;
}
.positive {
color: #F44336; /* 涨为红色(同花顺风格) */
}
.negative {
color: #4CAF50; /* 跌为绿色(同花顺风格) */
}
footer {
margin-top: 50px;
text-align: center;
color: #666;
font-size: 14px;
padding-top: 20px;
border-top: 1px solid #333;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>FenshiChart</h1>
<div class="subtitle">轻量级JavaScript分时图表库,支持实时数据更新、横向滚动和价格均线</div>
</header>
<div class="section">
<div id="demo-chart" class="chart-container"></div>
<div class="controls">
<button id="btn-add-data">添加数据点</button>
<button id="btn-start-simulation">开始模拟</button>
<button id="btn-reset">重置图表</button>
</div>
</div>
<div class="section">
<h2>更多演示</h2>
<div class="demo-links">
<a href="real-time-demo.html" class="demo-link">
<h3>实时数据演示</h3>
<p>更完整的实时数据演示,包含更多的配置选项和控制功能</p>
</a>
<a href="fixed-bar-example.html" class="demo-link">
<h3>固定柱宽示例</h3>
<p>使用固定柱宽模式,更适合展示大量数据点的分时图</p>
</a>
<a href="screenshot-match.html" class="demo-link">
<h3>截图模式</h3>
<p>使用固定数据生成与参考图像匹配的分时图,便于比较和调试</p>
</a>
<a href="stocks-grid.html" class="demo-link">
<h3>多股票网格视图</h3>
<p>以网格方式展示多支股票的实时行情,模拟市场总览界面</p>
</a>
</div>
</div>
<footer>
© 2023 FenshiChart | <a href="https://github.com/yourusername/fenshi-chart" style="color: #888;">GitHub</a>
</footer>
</div>
<script src="fenshi.js"></script>
<script>
// 创建图表实例
const chart = new FenshiChart('demo-chart', {
height: 350,
backgroundColor: '#0e1117',
lineColor: '#36a2eb',
averageColor: '#ffcd56',
gridColor: '#333',
textColor: '#888',
upBarColor: '#F44336', // 涨为红色(同花顺风格)
downBarColor: '#4CAF50', // 跌为绿色(同花顺风格)
showAverage: true,
animation: true,
padding: { top: 20, right: 60, bottom: 30, left: 60 }
});
// 生成初始数据
let price = 100;
let time = new Date();
time.setHours(9, 30, 0); // 设置初始时间为9:30
// 生成初始数据
const initialData = [];
for (let i = 0; i < 60; i++) {
// 模拟价格变动
const change = (Math.random() - 0.5) * 2;
price = Math.max(90, Math.min(110, price + change));
// 模拟成交量
const volume = Math.floor(Math.random() * 5000) + 1000;
// 随机生成买卖方向
const directions = ['buy', 'sell', 'neutral'];
const direction = directions[Math.floor(Math.random() * directions.length)];
// 添加数据点
initialData.push({
time: new Date(time),
price: price,
volume: volume,
direction: direction // 添加买卖方向
});
// 时间增加1分钟
time = new Date(time.getTime() + 60000);
}
// 设置初始数据
chart.setInitialData(initialData);
// 获取控制元素
const btnAddData = document.getElementById('btn-add-data');
const btnStartSimulation = document.getElementById('btn-start-simulation');
const btnReset = document.getElementById('btn-reset');
// 模拟间隔
let simulationInterval = null;
// 添加数据点
function addDataPoint() {
// 更新时间和价格
time = new Date(time.getTime() + 60000);
const change = (Math.random() - 0.5) * 2;
price = Math.max(90, Math.min(110, price + change));
// 随机成交量
const volume = Math.floor(Math.random() * 5000) + 1000;
// 随机生成买卖方向
const directions = ['buy', 'sell', 'neutral'];
const direction = directions[Math.floor(Math.random() * directions.length)];
// 添加数据点
chart.addData({
time: time,
price: price,
volume: volume,
direction: direction // 添加买卖方向
});
}
// 开始模拟
function startSimulation() {
if (simulationInterval) {
clearInterval(simulationInterval);
btnStartSimulation.textContent = '开始模拟';
simulationInterval = null;
} else {
simulationInterval = setInterval(addDataPoint, 1000);
btnStartSimulation.textContent = '停止模拟';
}
}
// 重置图表
function resetChart() {
// 停止模拟
if (simulationInterval) {
clearInterval(simulationInterval);
simulationInterval = null;
btnStartSimulation.textContent = '开始模拟';
}
// 重置价格和时间
price = 100;
time = new Date();
time.setHours(9, 30, 0);
// 重新生成数据并设置
chart.setInitialData(initialData);
}
// 绑定事件
btnAddData.addEventListener('click', addDataPoint);
btnStartSimulation.addEventListener('click', startSimulation);
btnReset.addEventListener('click', resetChart);
// 处理窗口调整大小
window.addEventListener('resize', () => {
const demoChart = document.getElementById('demo-chart');
chart.resize(demoChart.clientWidth);
});
</script>
</body>
</html>