-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstock2.htm
565 lines (510 loc) · 14.5 KB
/
stock2.htm
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
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>测试K线图</title>
<script type="text/javascript" src="jquery-2.0.0.min.js"></script>
<style type="text/css">
${demo.css}
</style>
<script type="text/javascript">
$(function() {
//K线图
$.getJSON('http://xueqiu.com/stock/forchartk/stocklist.json?period=1day&symbol=SZ002261&type=normal&callback=?', function(fdata) {
//修改colum条的颜色(重写了源码方法)
var originalDrawPoints = Highcharts.seriesTypes.column.prototype.drawPoints;
Highcharts.seriesTypes.column.prototype.drawPoints = function () {
var merge = Highcharts.merge,
series = this,
chart = this.chart,
points = series.points,
i = points.length;
while (i--) {
var candlePoint = chart.series[0].points[i];
if(candlePoint.open != undefined && candlePoint.close != undefined){ //如果是K线图 改变矩形条颜色,否则不变
var color = (candlePoint.open < candlePoint.close) ? '#DD2200' : '#33AA11';
var seriesPointAttr = merge(series.pointAttr);
seriesPointAttr[''].fill = color;
seriesPointAttr.hover.fill = Highcharts.Color(color).brighten(0.3).get();
seriesPointAttr.select.fill = color;
}else{
var seriesPointAttr = merge(series.pointAttr);
}
points[i].pointAttr = seriesPointAttr;
}
originalDrawPoints.call(this);
}
//常量本地化设置
Highcharts.setOptions({
global: {
useUTC: false
},
lang: {
rangeSelectorFrom:"日期",
rangeSelectorTo:"至",
rangeSelectorZoom:"范围"
},
shortMonths:['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
weekdays:['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
});
var $reporting = $("#report");
// split the data set into ohlc and volume
var ohlc = [],
volume = [],
chg = [],
percent = [],
turnrate = [],
ma5 = [],
ma10 = [],
ma20 = [],
ma30 = [],
dif = [],
dea = [],
macd = [],
buy = [],
sell = [],
symbol = fdata.stock.symbol,
data = fdata.chartlist,
dataLength = data.length;
for (i = 0; i < dataLength; i++) {
var timeStamp = (new Date(data[i].time)).getTime();
ohlc.push([
timeStamp, // the date
data[i].open, // open
data[i].high, // high
data[i].low, // low
data[i].close // close
]);
ma5.push([
timeStamp,
data[i].ma5
]);
ma10.push([
timeStamp,
data[i].ma10
]);
ma20.push([
timeStamp,
data[i].ma20
]);
ma30.push([
timeStamp,
data[i].ma30
]);
dif.push([
timeStamp,
data[i].dif
]);
dea.push([
timeStamp,
data[i].dea
]);
macd.push([
timeStamp,
data[i].macd
]);
volume.push([
timeStamp, // the date
data[i].volume // the volume
])
}
buy.push([1400688000000,5.3],
[1401033600000,5.0],
[1401379200000,4.2]);
sell.push([1401033600000,4.5],
[1402329600000,5.3],
[1403193600000,5.2]);
//console.log(ma20);
// set the allowed units for data grouping
/*var groupingUnits = [[
'week', // unit name
[1] // allowed multiples
], [
'month',
[1, 2, 3, 4, 6]
]];*/
// create the chart
$('#container').highcharts('StockChart', {
rangeSelector: {
inputEnabled: $('#container').width() > 480,
selected: 1,
inputDateFormat: '%Y/%m/%d',
inputEditDateFormat: '%Y/%m/%d',
buttons: [
{
type: 'month',
count: 1,
text: '1月'
}, {
type: 'month',
count: 3,
text: '3月'
}, {
type: 'month',
count: 6,
text: '6月'
}, {
type: 'ytd',
text: '至今'
}, {
type: 'year',
count: 1,
text: '1年'
}, {
type: 'all',
text: '所有'
}],
},
title: {
text: '('+symbol+')股票情况'
},
credits:{
text: 'jia58960',
href: 'http://jia58960.me'
},
tooltip: {
positioner: function () { //设置tips显示的相对位置
var halfWidth = this.chart.chartWidth/2;//chart宽度
var width = this.chart.chartWidth-155;
var height = this.chart.chartHeight/5-8;//chart高度
if(relativeWidth<halfWidth){
return { x: width, y:height };
}else{
return { x: 30, y: height };
}
},
xDateFormat: '%Y/%m/%d, %A',
formatter: function() {
if(this.y == undefined) {
return;
}
for (var i = 0; i < dataLength; i++) {
if(this.x == (new Date(data[i].time)).getTime() ){
percent = parseFloat(data[i].percent).toFixed(2);
chg = parseFloat(data[i].chg).toFixed(2);
turnrate = parseFloat(data[i].turnrate).toFixed(2);
zs = parseFloat(data[i-1].close).toFixed(2);
//console.log(percent);
}
}
open = this.points[0].point.open.toFixed(2);
high = this.points[0].point.high.toFixed(2);
low = this.points[0].point.low.toFixed(2);
close = this.points[0].point.close.toFixed(2);
y = (this.points[1].point.y*0.0001).toFixed(2);
MA5 =this.points[2].y.toFixed(2);
MA10 =this.points[3].y.toFixed(2);
MA20 =this.points[4].y.toFixed(2);
MA30 =this.points[5].y.toFixed(2);
relativeWidth = this.points[0].point.shapeArgs.x;
if (this.points[6]){
bPrice = this.points[6].y.toFixed(2);
} else {
bPrice = '';
}
if (this.points[7]){
sPrice = this.points[7].y.toFixed(2);
} else {
sPrice = '';
}
/*
*/
//DIF = this.points[0].point.dif.toFixed(2);
//DEA =
//return Highcharts.dateFormat('%Y-%m-%d', this.x) +'/';
var stockSymbol = this.points[0].series.name;
var tip = '<b>'+ Highcharts.dateFormat('%Y-%m-%d', this.x) +'</b><br/>';
if(open>zs){
tip += '开盘价:<span style="color: #DD2200;">'+open+' </span><br/>';
}else{
tip += '开盘价:<span style="color: #33AA11;">'+open+' </span><br/>';
}
if(high>zs){
tip += '最高价:<span style="color: #DD2200;">'+high+' </span><br/>';
}else{
tip += '最高价:<span style="color: #33AA11;">'+high+' </span><br/>';
}
if(low>zs){
tip += '最低价:<span style="color: #DD2200;">'+low+' </span><br/>';
}else{
tip += '最低价:<span style="color: #33AA11;">'+low+' </span><br/>';
}
if(close>zs){
tip += '收盘价:<span style="color: #DD2200;">'+close+' </span><br/>';
}else{
tip += '收盘价:<span style="color: #33AA11;">'+close+' </span><br/>';
}
if(chg>0){
tip += '涨跌额:<span style="color: #DD2200;">'+chg+' </span><br/>';
}else{
tip += '涨跌额:<span style="color: #33AA11;">'+chg+' </span><br/>';
}
if(percent>0){
tip += '涨跌幅:<span style="color: #DD2200;">'+percent+' %</span><br/>';
}else{
tip += '涨跌幅:<span style="color: #33AA11;">'+percent+' %</span><br/>';
}
if(y>10000){
tip += "成交量:"+(y*0.0001).toFixed(2)+"(亿股)<br/>";
}else{
tip += "成交量:"+y+"(万股)<br/>";
}
tip += "换手率:"+turnrate+"%<br/>";
if (bPrice!==''){
tip+='<strong style="color:#f00">买入:</strong>'+bPrice+"<br/>";
}
if(sPrice!==''){
tip+='<b style="color:#0f0">卖出:</b>'+sPrice+"<br/>";
}
$reporting.html(
' <span style="font-weight:bold">'+stockSymbol+'</span>'
+ ' <span>开盘:</span>'+ open
+' <span>收盘:</span>'+close
+' <span>最高:</span>'+ high
+' <span>最低:</span>'+ low
+' <span style="padding-left:15px;"> </span>'+ Highcharts.dateFormat('%Y-%m-%d',this.x)
+' <br/><b style="color:#1aadce;">MA5</b> '+ MA5
+' <b style="color: #8bbc21;padding-left:50px">MA10 </b> '+ MA10
+' <b style="color: #ffca53;padding-left:50px">MA20 </b> '+ MA20
+' <b style="color:#910000;padding-left:50px">MA30</b> '+ MA30
);
return tip;
},
},
plotOptions: {
spline: {
marker:{
states: {
hover: {
enabled: false
}
},
}
},
//修改蜡烛颜色
candlestick: {
color: '#33AA11',
upColor: '#DD2200',
lineColor: '#33AA11',
upLineColor: '#DD2200',
marker:{
states:{
hover:{
enabled:false,
}
}
}
},
line: {
cursor: 'pointer',
marker: {
enabled: true,
states: {
hover: {
lineWidthPlus: 1,
radiusPlus: 1
}
},
},
point:{
events: {
mouseOver: function(){
console.log(this);
}
}
}
},
},
xAxis: {
tickPixelInterval: 150,
type: 'datetime',
dateTimeLabelFormats: {
second: '%Y-%m-%d<br/>%H:%M:%S',
minute: '%Y-%m-%d<br/>%H:%M',
hour: '%Y-%m-%d<br/>%H:%M',
day: '%Y/%m/%d',
week: '%Y/%m/%d',
month: '%Y/%m',
year: '%Y'
}
},
yAxis: [{
labels: {
align: 'right',
x: -5
},
tickInterval: 2,
title: {
text: 'OHLC'
},
height: '60%',
lineWidth: 1
}, {
labels: {
align: 'right',
x: -3
},
title: {
text: '成交量'
},
top: '65%',
height: '35%',
offset: 0,
lineWidth: 1
}],
series: [
{
type: 'candlestick',
name: symbol,
data: ohlc,
dataGrouping: {
enabled: false
}
}, {
type: 'column',
name: '成交量',
data: volume,
yAxis: 1,
dataGrouping: {
enabled: false
}
},
{
type: 'spline',
name: 'MA5',
color:'#1aadce',
data: ma5,
lineWidth:1,
dataGrouping: {
enabled: false
}
},{
type: 'spline',
name: 'MA10',
data: ma10,
color:'#8bbc21',
threshold: null,
lineWidth:1,
dataGrouping: {
enabled: false
}
},{
type: 'spline',
name: 'MA20',
data: ma20,
color:'#ffca53',
threshold: null,
lineWidth:1,
dataGrouping: {
enabled: false
}
},{
type: 'spline',
name: 'MA30',
data: ma30,
color:'#910000',
threshold: null,
lineWidth:1,
dataGrouping: {
enabled: false
}
}/*,{
type: 'line',
name: '买入情况',
data: buy,
color: '#FFE9A3',
lineWidth: 2,
marker: {
lineWidth: 1,
radius: 5
}
},
{
type: 'line',
name: '卖出情况',
data: sell,
color: '#A656E8',
lineWidth: 2,
marker: {
lineWidth: 1,
radius: 5
}
}*/
]
});
});
//持股总览
$('#container2').highcharts({
chart: {
type: 'bar'
},
title: {
text: '乐视网(300104)持股一览表'
},
subtitle: {
text: '(目前为止乐视网持股情况)'
},
xAxis: {
min: 0,
categories: ['5.62', '5.78', '5.93', '6.20', '6.31', '6.43', '6.51'],
title: {
text: '买入单价(元)',
style: {
fontFamily: 'microsoft yahei',
fontSize: '14px',
align: 'left'
}
}
},
yAxis: {
min: 0,
title: {
text: '持股数量 (手)',
style: {
fontFamily: 'microsoft yahei',
fontSize: '14px',
align: 'left'
}
}
},
tooltip: {
formatter: function() {
return '<b>'+this.x+'元:'+ this.y +'手</b>';
}
},
legend: {
align: 'right',
verticalAlign: 'top',
enabled: false,
borderWidth: 1,
shadow: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: [
{
name: '持股数: ',
data: [9, 5, 4, 2, 6, 1, 7]
}
]
});
});
</script>
</head>
<body>
<script src="Highstock/js/highstock.js"></script>
<script src="Highstock/js/modules/exporting.js"></script>
<div id="report" style="height:50px;padding-top:5px;width:800px;font-family:microsoft yahei"></div>
<div id="container" style="height: 500px; width: 800px;margin:0px auto;"></div>
<div id="container2" style="min-width: 310px; width: 600px; height: 400px; margin:5px;float:left"></div>
<div style="clear:both"></div>
</body>
</html>