-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstock3.htm
218 lines (185 loc) · 4.94 KB
/
stock3.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
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highstock Example</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() {
var getCurrentD=function(){
$.getJSON('http://xueqiu.com/stock/quotec.json?code=SZ002261&callback=?',
function(cdata){
var cPrice = cdata[0][1],
cRate = cdata[0][2],
cPercentage = cdata[0][3];
if (cRate<0){
$("#currentQuote").css('color','#338833');
} else {
$("#currentQuote").css('color','#cc1100');
cRate = '+'+cRate;
cPercentage = '+'+cPercentage;
}
$("#currentQuote").html('<span style="font-size:34px;font-weight:bold">¥'+cPrice+'</span><span style="font-size:16px">'+cRate+'('+cPercentage+'%)</span>');
})
};
getCurrentD();
var d = new Date(),hour = d.getHours();
//上午9-12、下午13-16执行
if ((hour >= 9 && hour <= 11) || (hour >= 13 && hour <=15)){
setInterval(getCurrentD,2000);
}
var hDataFunc = function(){
$.getJSON('http://xueqiu.com/stock/forchart/stocklist.json?symbol=SZ002261&period=1d&callback=?', function(fdata) {
var data = fdata.chartlist,
lineData = [],
volData = [],
symbol = fdata.stock.symbol,
dataLength = data.length;
for (i = 0; i < dataLength; i++) {
var timeStamp = (new Date(data[i].time)).getTime();
lineData.push([
timeStamp,
data[i].current
]);
volData.push([
timeStamp,
data[i].volume
])
}
//常量本地化设置
Highcharts.setOptions({
global: {
useUTC: false
},
lang: {
rangeSelectorFrom:"日期",
rangeSelectorTo:"至",
rangeSelectorZoom:"范围"
},
shortMonths:['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
weekdays:['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
});
// Create the chart
$('#container').highcharts('StockChart', {
chart : {
events : {
load : function() {
// set up the updating of the chart each second
var series = this.series[0],series2 = this.series[1];
if ((hour >= 9 && hour <= 11) || (hour >= 13 && hour <=15)){
setInterval(function() {
$.getJSON('http://xueqiu.com/stock/forchart/stocklist.json?symbol=SZ002261&period=1d&callback=?', function(data) {
var ndata = data.chartlist[data.chartlist.length-1];
var y = ndata.current, // current time
x = (new Date(ndata.time)).getTime(),
z = ndata.volume;
console.log(x);
console.log(y);
console.log(z);
series.addPoint([x, y], true, true);
series2.addPoint([x,z], true, true);
});
}, 180000); //每三分钟获取一次
}
}
}
},
rangeSelector : {
enabled:false
},
title: {
text: '('+symbol+')股票分时图'
},
credits: {
text: 'jia58960',
href: 'http://jia58960.me',
position: {
align: 'right',
x: -15,
verticalAlign: 'bottom',
y: -2
}
},
tooltip: {
xDateFormat: '%Y/%m/%d, %A',
/*formatter: function(){
if(this.y == undefined) {
return;
}
console.log(this.points[0]);
//current = this.points[0].point.current.toFixed(2);
//return ;
var stockSymbol = this.points[0].series.name;
}*/
},
series : [{
name : symbol,
data : lineData,
tooltip: {
valueDecimals: 2
}
},{
type: 'column',
name: '成交量',
data: volData,
yAxis: 1,
dataGrouping: {
enabled: false
}
}],
xAxis: {
tickPixelInterval: 150,
type: 'datetime',
dateTimeLabelFormats: {
second: '%H:%M:%S',
minute: '%H:%M',
hour: '%H:%M',
day: '%Y/%m/%d',
week: '%Y/%m/%d',
month: '%Y/%m',
year: '%Y'
}
},
yAxis: [{
labels: {
align: 'right',
x: -5
},
title: {
text: 'OHLC'
},
height: '60%',
lineWidth: 1
}, {
labels: {
align: 'right',
x: -3
},
title: {
text: '成交量'
},
top: '65%',
height: '35%',
offset: 0,
lineWidth: 1
}]
});
});
}
hDataFunc();
//setInterval(hDataFunc,5000);
});
</script>
</head>
<body>
<script src="Highstock/js/highstock.js"></script>
<!-- <script src="Highstock/js/themes/dark-blue.js"></script> -->
<script src="Highstock/js/modules/exporting.js"></script>
<div id="currentQuote" style="width:600px;margin:0 auto;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif">
</div>
<div id="container" style="height: 400px; width: 600px;margin:0 auto"></div>
</body>
</html>