var intradayChart = { chart : null, type : null, fromdate : null, todate : null, mode : "desktop", container : "", lineWidth: 2, init : function(code){ var self = this; self.labels["edu"] = self.labels["zh_cn"]; self.labels["edu-zh_hk"] = self.labels["zh_hk"]; self.labels["edu-zh_cn"] = self.labels["zh_cn"]; self.labels["edu-en_hk"] = self.labels["en_hk"]; //self.mode = (window.innerWidth<991)?"mobile":"desktop"; $.getJSON('/?q=/'+lang+'/data/chart/intradayChart/code/'+code, function(_data) { var data = self.decode(_data); $('#intradayChartContainer').highcharts('StockChart',self.getJSON(data), function (chart){ self.chart = chart; self.drawBackground(); }); }); }, decode : function(_data){ return _data.mainData; }, colors : {line1 : "#88abd5", line2 : "#ed8b00"}, margin : {mobile: 70, desktop: 100}, getJSON : function(data){ var self = this; var max = data.max; var min = data.min; var last = data.last; var lastc = data.lastc; var turnover = data.turnover; var turnover_unit = data.turnover_unit; var y_visible = true; if(last.length>0){ var last_date = Highcharts.dateFormat('%Y-%m-%d', last[0][0]); var endTime = new Date(last_date+' 17:00:00 GMT').getTime(); for (var i=0;i-1) { self.halfday = false; } }; }else{ y_visible = false; } if(max==min){ if(min<0.05){ min = 0; max = 0.05; }else{ max = max*1.5; min = min*0.5; } } return { chart : { useHTML: true, plotBorderWidth: 0, marginTop: 10, marginRight: (y_visible)?50:0, height: 218, //width: 335, events: { redraw: function(event) { self.redraw(); } } }, plotOptions: { series: { grouping: false, connectNulls: true } }, tooltip: { useHTML: true, formatter: function() { var _html = '
'+Highcharts.dateFormat('%Y-%m-%d', this.x)+' '+Highcharts.dateFormat('%H:%M', this.x)+''; if(last[this.points[0].point.index][1]!=null){ _html += '
'+self.labels[lang].price+': '+ addcomma(last[this.points[0].point.index][1])+''; }else{ _html += '
'+self.labels[lang].price+': - '; } if(turnover[this.points[0].point.index]!=null){ _html += '
'+self.labels[lang].turnover+': '+turnover[this.points[0].point.index]+''; }else{ _html += '
'+self.labels[lang].turnover+': - '; } return _html; }, }, rangeSelector : { inputEnabled:false, enabled: false }, xAxis:[ { type: 'datetime', gridLineWidth: 0, lineWidth: 0.5, tickWidth: 0, tickColor: '#ddd', lineColor: '#ddd', tickmarkPlacement: 'on', labels: { style: {color: "#000"}, rotation: 0, formatter : function() { //var value = Highcharts.dateFormat('%H:%M', this.value); var value = Highcharts.dateFormat('%H:%M', this.value); //console.log(value); if (self.halfday) { return value; } else { if (value.indexOf('12:00')>-1||value.indexOf('09:00')>-1||value.indexOf('17:00')>-1) { return ''; } else if (value.indexOf('13:00')>-1) { return '12/13'; } else { return value; } } } }, tickPositioner: function () { //tickPositioner for daily var positions = []; var msec = 60*60*1000; var lastday = 0; if(last.length>0){ for (i=0;i-1||value.indexOf('09:')>-1||value.indexOf('17:00')>-1)) { if (lastday != _today){ lastday = _today; positions.push(data.last[i][0]); } } } } return positions; }, } ], yAxis: [ { //visible: y_visible, title: { useHTML: false, text: "", }, labels:{ enabled : y_visible, align:'right', x: 40, //y: 15, y: 5, formatter: function () { return (this.isFirst)?"":this.value; }, style: {color: "#88abd5"} }, opposite: true, tickAmount : 6, showLastLabel: true, gridLineDashStyle: 'Solid', max: max, min: min, plotLines: [{ value: lastc, width: 2, color: this.colors["line2"], dashStyle: 'Solid', label: { //useHTML: true, //text: '
'+lastc+'
', text: lastc, align: 'right', x: 50, y: 5 } }] } ], navigator : { enabled : false, }, scrollbar : { enabled : false }, series : [ { data : last, useHTML: true, color: this.colors["line1"], lineWidth: 2 } ], exporting: { enabled: false } }; }, redraw: function(){ var chart = this.chart; var offsetx,offsety; var self = this; var offsetx = 20; var offsety = 30; // var textbox = chart.yAxis[ 0 ].plotLinesAndBands[ 0 ].label; // var box = textbox.getBBox(); // $("#drawPlotLinesRect").remove(); // $("#drawPlotLinesText").remove(); // chart.renderer.rect(chart.plotWidth+10, box.y-4, 50,20, 0).attr({ // fill: "#f8a140", // 'stroke-width': 0, // id : 'drawPlotLinesRect', // zIndex: 7, // }).add(); // var label = chart.renderer.label(textbox.textStr, chart.plotWidth+5 , box.y-4, '', '' + '', '' + '') // .css({ // color: "#fff", // fontSize:'12px', // width: box.width // }) // .attr({ // zIndex: 7, // fill: "#f8a140", // width: box.width, // r: 0, // id: 'drawPlotLinesText' // }) // .add(); // label.attr({ // x: chart.plotWidth + chart.plotLeft + (50-label.width)/2 // }); if(chart.yAxis[ 0 ].plotLinesAndBands.length>0){ var textbox = chart.yAxis[ 0 ].plotLinesAndBands[ 0 ].svgElem.d; var value = chart.yAxis[ 0 ].plotLinesAndBands[ 0 ].options.value; var d = textbox.split(" "); $("#drawPlotLinesRect").remove(); $("#drawPlotLinesText").remove(); chart.renderer.rect(chart.plotWidth+10, d[5]*1-10, 50,20, 0).attr({ fill: "#f8a140", 'stroke-width': 0, id : 'drawPlotLinesRect', zIndex: 7, }).add(); var label = chart.renderer.label(value, chart.plotWidth+5 , d[5]*1-10, '', '' + '', '' + '') .css({ color: "#fff", fontSize:'12px', width: chart.plotRight }) .attr({ zIndex: 7, fill: "#f8a140", width: chart.plotRight, r: 0, id: 'drawPlotLinesText' }) .add(); label.attr({ x: chart.plotWidth + chart.plotLeft + (50-label.width)/2 }); } }, adddText: function(x,y,text,i, color){ var chart = this.chart; $("#drawLegendRect"+i).remove(); $("#drawLegendText"+i).remove(); chart.renderer.rect(x, y, 25,8, 0).attr({ fill: color, 'stroke-width': 0, id : 'drawLegendRect'+i, zIndex: 5, }).add(); chart.renderer.label(text, x+30, y-8, '', '' + '', '' + '') .css({ color: color, fontSize:'15px' }) .attr({ zIndex: 5, id: 'drawLegendText'+i, }) .add(); }, drawBackground: function(){ var chart = this.chart; var offsetx,offsety; var self = this; this.redraw(); }, labels : { zh_hk :{ warrant:{ typetext : "認股證", textmsg : "認股證價格
(港元)
" }, cbbc:{ typetext : "牛熊證", textmsg : "牛熊證價格
(港元)
" }, price : "價格", turnover : "成交額", time : "時間" }, zh_cn :{ warrant:{ typetext : "认股证", textmsg : "认股证价格
(港元)
" }, cbbc:{ typetext : "牛熊证", textmsg : "牛熊证价格
(港元)
" }, price : "价格", turnover : "成交额", time : "时间" }, en_hk :{ warrant:{ typetext : "Warrants", textmsg : "Warrants Price
(HKD)
" }, cbbc:{ typetext : "CBBCs", textmsg : "CBBCs Price
(HKD)
" }, price : "Price", turnover : "Turnover", time : "Time" }, } }