This repository has been archived by the owner on Apr 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
604 lines (554 loc) · 25.1 KB
/
index.html
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Quotation</title>
<style type="text/css">
#timesharing {
width: 800px;
height: 400px;
}
</style>
<script src="jquery-2.2.3.js"></script>
<script src="highstock.src.js"></script>
</head>
<body>
<div id="container">
<div id="timesharing"></div>
</div>
<script type="application/javascript">
$(document).ready(function () {
showCharts();
});
</script>
</body>
<script type="application/javascript">
var tsTimeList, tsDataList, tsData, stockName, stockCode,
price_max, price_min, pre_close, quotationData, volume, price;
tsTimeList = new Array();
tsDataList = new Array();
tsData = new Array();
quotationData = new Array();
volume = new Array();
price = new Array();
stockCode = '600490';
stockName = '鹏欣资源';
pre_close = 6.52;
price_max = Math.ceil(pre_close * 1.1 * 100) / 100;
price_min = Math.floor(pre_close * 0.9 * 100) / 100;
var yesterdayClose = pre_close;
function getData() {
//Data preparing
//get data
var tickJsonURL, quotationData;
tickJsonURL = 'http://localhost:63342/quotation/' + stockCode + '_ticks.json';
$.getJSON(tickJsonURL,
function (data) {
quotationData = data.data.reverse();
var timeString = '';
var UTCTime, minLastFlag, minCurFlag, minTotalVol,
minTotalPrice, minLastPrice, minTickCount, UTCTimeNmber;
minTickCount = 0;
minTotalVol = 0;
minTotalPrice = 0;
minLastFlag = Number(quotationData[0][0].substr(3, 2));
//Combine ticks by minute
for (var i = 0; i < quotationData.length; i++) {
timeString = quotationData[i][0];
minCurFlag = Number(timeString.substr(3, 2));
minLastPrice = quotationData[i][1];
if (minCurFlag !== minLastFlag) {
//A new minute, write down the last one
UTCTimeNmber = Number(Date.UTC(
2016,
4,
13,
Number(timeString.substr(0, 2)),
minLastFlag));
tsData.push([UTCTimeNmber, minTotalPrice / minTickCount,
minTotalVol, minLastPrice]);
minLastFlag = minCurFlag;
minTickCount = 0;
minTotalVol = 0;
minTotalPrice = 0;
}
minTickCount = minTickCount + 1;
minTotalVol = minTotalVol + quotationData[i][4];
minTotalPrice = minTotalPrice + quotationData[i][1];
}
}
);
}
function showCharts() {
getData();
alert(tsData);
var last_dataTime = new Date();
// Create the chart
var am_startTime = new Date(last_dataTime);
am_startTime.setHours(9, 30, 0, 0);
var am_startTimeUTC = Number(Date.UTC(am_startTime.getFullYear(), am_startTime.getMonth(), am_startTime.getDate(), am_startTime.getHours(), am_startTime.getMinutes()));
var am_midTime = new Date(last_dataTime);
am_midTime.setHours(10, 30, 0, 0);
var am_midTimeUTC=Number(Date.UTC(am_midTime.getFullYear(),am_midTime.getMonth(),am_midTime.getDate(),am_midTime.getHours(),am_midTime.getMinutes()));
//股票交易早上最后的时间
var am_lastTime = new Date(last_dataTime);
am_lastTime.setHours(11, 30, 0, 0);
var am_lastTimeUTC = Number(Date.UTC(am_lastTime.getFullYear(), am_lastTime.getMonth(), am_lastTime.getDate(), am_lastTime.getHours(), am_lastTime.getMinutes()));
//股票交易下午最后的时间
var pm_startTime = new Date(last_dataTime);
pm_startTime.setHours(13, 1, 0, 0);
var pm_startTimeUTC = Number(Date.UTC(pm_startTime.getFullYear(), pm_startTime.getMonth(), pm_startTime.getDate(), pm_startTime.getHours(), pm_startTime.getMinutes()));
var pm_midTime = new Date(last_dataTime);
pm_midTime.setHours(14, 0, 0, 0);
var pm_midTimeUTC = Number(Date.UTC(pm_midTime.getFullYear(), pm_midTime.getMonth(), pm_midTime.getDate(), pm_midTime.getHours(), pm_midTime.getMinutes()));
var pm_lastTime = new Date(last_dataTime);
pm_lastTime.setHours(15, 0, 0, 0);
var pm_lastTimeUTC = Number(Date.UTC(pm_lastTime.getFullYear(), pm_lastTime.getMonth(), pm_lastTime.getDate(), pm_lastTime.getHours(), pm_lastTime.getMinutes()));
//常量本地化
Highcharts.setOptions({
global: {
useUTC: true
}
});
var avg_pxyAxisMin;
var avg_pxyAxisMax;
var percentageyAxisMin;
var percentageyAxisMax;
var volume_yAxisMin;
var volume_yAxisMax;
var red = "#ff0000";
var blue = "#00a800";
var columnColor = red;
for (var i = 0; i < tsData.length; i += 1) {
var dateUTC = tsData[i][0];
var business_amount = tsData[i][2];
if (i == 0) {//第一笔的 红绿柱 判断依据是根据 今天开盘价与昨日收盘价比较
avg_pxyAxisMin = tsData[i][1];
avg_pxyAxisMax = tsData[i][1];
percentageyAxisMin = Number(100 * (tsData[i][1] / yesterdayClose - 1));
percentageyAxisMax = Number(100 * (tsData[i][1] / yesterdayClose - 1));
}
else {
business_amount = tsData[i][2] - tsData[i - 1][2];
}
if (tsData[i][1] < tsData[i][3]) {
columnColor = red;
}else{
columnColor = blue;
}
avg_pxyAxisMin = avg_pxyAxisMin > tsData[i][1] ? tsData[i][1] : avg_pxyAxisMin;
avg_pxyAxisMax = avg_pxyAxisMax > tsData[i][1] ? avg_pxyAxisMax : tsData[i][1];
percentageyAxisMin = percentageyAxisMin > Number(100 * (tsData[i][1] / yesterdayClose - 1)) ? Number(100 * (tsData[i][1] / yesterdayClose - 1)) : percentageyAxisMin;
percentageyAxisMax = percentageyAxisMax > Number(100 * (tsData[i][1] / yesterdayClose - 1)) ? percentageyAxisMax : Number(100 * (tsData[i][1] / yesterdayClose - 1));
volume_yAxisMin = volume_yAxisMin > business_amount ? business_amount : volume_yAxisMin;
volume_yAxisMax = volume_yAxisMax > business_amount ? volume_yAxisMax : business_amount;
volume.push({x: dateUTC, y: tsData[i][2], color: columnColor});
}
// appendTimeMessage(tsData, volume);
$('#timesharing').highcharts('StockChart', {
chart: {
panning: false,
zoomType: 'none',
pinchType: 'none',
renderTo: "line_map",
margin: [25, 25, 25, 25],
spacing: [0, 0, 0, 0],
plotBorderColor: '#3C94C4',
plotBorderWidth: 0,
events: {
load: function () {
x = tsData[tsData.length - 1][0];
y = tsData[tsData.length - 1][1];
var chart = $('#timesharing').highcharts(); // Highcharts构造函数
//基准线
chart.yAxis[0].addPlotLine({ //在x轴上增加
value: yesterdayClose, //在值为2的地方
width: 0.1, //标示线的宽度为2px
color: '#FFA500', //标示线的颜色
zIndex: 1001
});
chart.xAxis[0].removePlotBand("plotBand-x");
chart.xAxis[0].addPlotBand({
borderColor: '#BEBEBE',
borderWidth: 0.1,
color: '#BEBEBE',
from: tsData[tsData.length - 1][0] - 0.000001,//,Date.UTC(2015, 3, 27,10,50),
to: tsData[tsData.length - 1][0] + 0.000001,//Date.UTC(2015, 3, 27,10,51),
label: {
useHTML: true,
text: '<span class="value" style="font-size:10px;background-color:rgba(0,0,0,.6); color:#fff; height:15px; line-height:15px; padding:0 5px;">' + Highcharts.dateFormat('%H:%M ', tsData[tsData.length - 1][0]) + '</span>',
textAlign: 'top',
y: 5,
x: -30
},
id: 'plotBand-x',
zIndex: 1001
});
chart.yAxis[0].removePlotBand("plotBand-y0");
chart.yAxis[0].addPlotBand({
borderColor: '#BEBEBE',
borderWidth: 0.1,
color: '#BEBEBE',
from: tsData[tsData.length - 1][1] - 0.0001,//,Date.UTC(2015, 3, 27,10,50),
to: tsData[tsData.length - 1][1] + 0.0001,//Date.UTC(2015, 3, 27,10,51),
label: {
useHTML: true,
style: { //字体样式
font: 'normal 8px Verdana, sans-serif'
},
text: '<span class="value" style="font-size:10px;background-color:rgba(0,0,0,.6); color:#fff; height:15px; line-height:15px; padding:0 5px;">' + tsData[tsData.length - 1][1].toFixed(2) + '</span>',
verticalAlign: 'top',
textAlign: 'left',
x: -25,
y: -2
},
id: 'plotBand-y0',
zIndex: 1001
});
chart.yAxis[0].removePlotBand("plotBand-y1");
chart.yAxis[0].addPlotBand({
color: '#BEBEBE',
borderWidth: 0.1,
borderColor: '#BEBEBE',
from: tsData[tsData.length - 1][1] - 0.0001,//,Date.UTC(2015, 3, 27,10,50),
to: tsData[tsData.length - 1][1] + 0.0001,//Date.UTC(2015, 3, 27,10,51),
label: {
useHTML: true,
style: { //字体样式
font: 'normal 8px Verdana, sans-serif'
},
text: '<span class="value" style="font-size:10px;background-color:rgba(0,0,0,.6); color:#fff; height:15px; line-height:15px; padding:0 5px;">' + (100 * (tsData[tsData.length - 1][1] / yesterdayClose - 1)).toFixed(2) + "%" + '</span>',
textAlign: 'right',
verticalAlign: 'bottom',
x: 280,
y: -2
},
id: 'plotBand-y1',
zIndex: 1001
});
}
}
},
title: {
text: stockName + ' (' + stockCode + ')'
},
subtitle: {
text: new Date() + ''
},
rangeSelector: {
enabled: false,
},
/*导出配置*/
exporting: {
enabled: false,
},
/*创建者信息*/
credits: {
enabled: false,
},
/*下部时间拖拉选择*/
navigator: {
enabled: false,
/*关闭时间选择*/
baseseries: 10
},
scrollbar: {
enabled: false /*关闭下方滚动条*/
},
xAxis: {
showFirstLabel: true,
showLastLabel: true,
scrollbar: {enabled: true},
labels: {
// staggerLines:5
style: { //字体样式
font: 'normal 8px Verdana, sans-serif'
},
formatter: function () {
var returnTime = Highcharts.dateFormat('%H:%M ', this.value);
if (returnTime == "11:30 ") {
return "11:30/13:00";
}
return returnTime;
},
},
tickPositioner: function () {
var positions = [am_startTimeUTC, am_midTimeUTC, am_lastTimeUTC, pm_midTimeUTC, pm_lastTimeUTC];
return positions;
},
gridLineWidth: 1,
},
yAxis: [{
opposite: false,//是否把它显示到另一边(右边)
labels: {
style: { //字体样式
font: 'normal 8px Verdana, sans-serif'
},
overflow: 'justify',
align: 'right',
x: -3,
y: 5,
formatter: function () {
//最新价 px_last/preclose昨收盘-1
return (this.value).toFixed(2);
}
},
title: {
text: ''
},
top: '0%',
height: '65%',
lineWidth: 1,
showFirstLabel: true,
showLastLabel: true,
tickPositioner: function () { //以yesterdayClose为界限,统一间隔值,从 最小到最大步进
positions = [],
tick = Number((avg_pxyAxisMin)),
increment = Number(((avg_pxyAxisMax - avg_pxyAxisMin) / 5));
var tickMin = Number((avg_pxyAxisMin)), tickMax = Number((avg_pxyAxisMax));
if (0 == tsData.length) {//还没有数据时,yesterdayClose 的幅值 在 -1% - 1%上下浮动
tickMin = 0.99 * yesterdayClose;
tickMax = 1.01 * yesterdayClose;
} else if (0 == increment) {//有数据了 但是数据都是一样的幅值
if (yesterdayClose > Number(avg_pxyAxisMin)) {
tickMin = Number(avg_pxyAxisMin);
tickMax = 2 * yesterdayClose - Number(avg_pxyAxisMin);
} else if (yesterdayClose < Number(avg_pxyAxisMin)) {
tickMax = Number(avg_pxyAxisMax);
tickMin = yesterdayClose - (Number(avg_pxyAxisMax) - yesterdayClose);
} else {
tickMin = 0.99 * yesterdayClose;
tickMax = 1.01 * yesterdayClose;
}
} else if (avg_pxyAxisMin - yesterdayClose < 0 && avg_pxyAxisMax - yesterdayClose > 0) {//最小值在昨日收盘价下面,最大值在昨日收盘价上面
var limit = Math.max(Math.abs(avg_pxyAxisMin - yesterdayClose), Math.abs(avg_pxyAxisMax - yesterdayClose));
tickMin = yesterdayClose - limit;
tickMax = yesterdayClose + limit;
} else if (avg_pxyAxisMin > yesterdayClose && avg_pxyAxisMax > yesterdayClose) {//最小最大值均在昨日收盘价上面
tickMax = avg_pxyAxisMax;
tickMin = yesterdayClose - (tickMax - yesterdayClose);
} else if (avg_pxyAxisMin < yesterdayClose && avg_pxyAxisMax < yesterdayClose) {//最小最大值均在昨日收盘价下面
tickMin = avg_pxyAxisMin;
tickMax = yesterdayClose + (yesterdayClose - tickMin);
}
if (tickMax > 2 * yesterdayClose) {//数据超过100%了
tickMax = 2 * yesterdayClose;
tickMin = 0;
}
var interval = Number(tickMax - yesterdayClose) / 10;
tickMax += interval;
tickMin = yesterdayClose - (tickMax - yesterdayClose);
increment = (tickMax - yesterdayClose) / 3;
tick = tickMin;
var i = 0;
for (tick; i++ < 7; tick += increment) {
positions.push(Number(tick));
}
return positions;
},
},
{
opposite: true,//是否把它显示到另一边(右边)
showFirstLabel: true,
showLastLabel: true,
labels: {
overflow: 'justify',
style: { //字体样式
font: 'normal 8px Verdana, sans-serif'
},
align: 'right',
x: 25,
y: 15,
formatter: function () {//最新价 px_last/preclose昨收盘-1
return (100 * (this.value / yesterdayClose - 1)).toFixed(2) + "%";
}
},
title: {
text: ''
},
lineWidth: 1,
top: '0%',
height: '65%',
gridLineWidth: 1,
tickPositioner: function () {
return positions;
}
},
{
opposite: false,//是否把它显示到另一边(右边)
labels: {
overflow: 'justify',
style: { //字体样式
font: 'normal 8px Verdana, sans-serif'
},
align: 'right',
x: -3,
y: 5,
formatter: function () {
if (this.value > 1000000000) {
return Number((this.value / 1000000000).toFixed(2)) + "G";
} else if (this.value > 1000000) {
return Number((this.value / 1000000).toFixed(2)) + "M";
} else if (this.value > 1000) {
return Number((this.value / 1000).toFixed(2)) + "K";
} else {
return Number(this.value.toFixed(2));
}
}
},
title: {
text: ''
},
top: '70%',
height: '30%',
width: '100%',
offset: 0,
lineWidth: 1,
showFirstLabel: true,
showLastLabel: true,
tickPositioner: function () {
var positions = [],
tickMax = volume_yAxisMax,
tickMin = volume_yAxisMin,
tick = 0,
increment = 0;
var limit = tickMax / 2;
tickMax += limit;
increment = tickMax / 2;
tick = 0;
for (tick; tick <= tickMax; tick += increment) {
positions.push(Number(tick.toFixed(2)));
if (increment == 0) {
break;
}
}
return positions;
}
}],
series: [{
name: stockName,
data: tsData,
type: 'areaspline',
tooltip: {
valueDecimals: 2
},
fillColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, Highcharts.getOptions().colors[0]],
[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
]
},
yAxis: 0
},
{
name: stockName,
data: tsData,
type: 'scatter',
cursor: 'pointer',
onSeries: 'candlestick',
color: 'transparent',
tooltip: {
valueDecimals: 2
},
style: {
fontSize: '0px',
fontWeight: '0',
textAlign: 'center'
},
zIndex: -1000,
yAxis: 1
},
{
type: 'column',
name: '成交量',
data: volume,
dataGrouping: {
enabled: false,
forced: true
},
yAxis: 2,
zIndex: -1000
}]
});
}
/**
* 获取日期对象,如果isUTC为true获取 日期的UTC对象,false则获取普通日期对象
* @param date
* @param isUTC
* @returns
*/
function getDateUTCOrNot(date, isUTC) {
if (!(date instanceof String)) {
date += "";
}
//201605121109
var dArr = new Array();
for (var hh = 0; hh < 5; hh++) {
var numb;
if (hh == 0) {
numb = Number(date.slice(0, 4));
}
else {
numb = Number(date.slice((hh - 1) * 2 + 4, hh * 2 + 4));
}
;
dArr.push(numb);
}
if (isUTC == false) {
return new Date(dArr[0], dArr[1] - 1, dArr[2], dArr[3], dArr[4]);
}
var dateUTC = Number(Date.UTC(dArr[0], dArr[1] - 1, dArr[2], dArr[3], dArr[4]));//得出的UTC时间
return dateUTC;
}
//数据补全
function appendTimeMessage() {
var last_dataTime = new Date(tsData[tsData.length - 1][0]);
alert(last_dataTime);
//AM last
var am_lastTime = new Date(last_dataTime);
am_lastTime.setUTCHours(11, 30, 0, 0);
//PM start
var pm_startTime = new Date(last_dataTime);
pm_startTime.setUTCHours(13, 1, 0, 0);
//PM last
var pm_lastTime = new Date(last_dataTime);
pm_lastTime.setUTCHours(15, 0, 0, 0);
//把时间日期格式转化成utc格式
function convertDateToUTC(date) {
return Number(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes()));
}
//如果获取的时间11::30之前的计算
if (last_dataTime < am_lastTime) {
var i = last_dataTime;
i.setUTCMinutes((i.getUTCMinutes() + 1));
for (; i <= am_lastTime; i.setUTCMinutes((i.getUTCMinutes() + 1))) {
tsData.push([convertDateToUTC(i), undefined, undefined, undefined]);
volume.push([convertDateToUTC(i), undefined, undefined, undefined]);
}
i = pm_startTime;
for (; i <= pm_lastTime; i.setUTCMinutes((i.getUTCMinutes() + 1))) {
tsData.push([convertDateToUTC(i), undefined, undefined, undefined]);
volume.push([convertDateToUTC(i), undefined, undefined, undefined]);
}
} else if (last_dataTime < pm_lastTime) { //获取的时间下午13:00之后的计算
var i;
if (Number(last_dataTime) == Number(am_lastTime)) {
i = pm_startTime;
} else {
i = last_dataTime;
}
i.setUTCMinutes((i.getUTCMinutes() + 1));
for (; i <= pm_lastTime; i.setUTCMinutes((i.getUTCMinutes() + 1))) {
tsData.push([convertDateToUTC(i), undefined, undefined, undefined]);
volume.push([convertDateToUTC(i), undefined, undefined, undefined]);
}
}
}
</script>
</html>