var underlyingIntradayChart = { ucode : "", ucurrency: "", container : "", chart : null, init : function(ucode, ucurrency, code, callback){ var self = this; /*if(ucode == "") { ucode = 'hsi'; } self.ucode = ucode;*/ if (ucode != ""){ self.ucode = ucode; } if(ucurrency != "") { self.ucurrency = ucurrency; } if(code != "") { self.code = code; } $.getJSON('/'+lang+'/data/chart/underlyingIntradayChart?ucode='+self.ucode+'&ucurrency='+self.ucurrency+'&code='+self.code, function(_data) { var data = self.decode(_data); $((self.container=='')?'#underlyingIntradayChartContainer':'#'+self.container).highcharts('StockChart', self.getJSON(data), function(chart){ self.chart = chart; self.drawBackground(); if (callback!==undefined){ callback(chart,data); } }); }); }, decode : function(_data){ return _data; }, colors :{line: "#082A4D", lastc: "#F4842A", label: "#84888B", drawLine: "#08294E", xTooltip: "#606060", yTooltip: "#F28528", grey: "#8e8e8e"}, getJSON : function(_data){ //console.log(_data); var dp = 0; var close = []; var data = _data.mainData; var fdata = _data.furtherData; var min_last = fdata.lastc*1; var max_last = fdata.lastc*1; var groupingUnits = [['minute',[5]], ['hour',[1]]]; for (i = 0; i < data.length; i++) { if (data[i][1] == null) data[i][2] = null; if (min_last == 0 && data[i][1]*1 > 0) min_last = data[i][1]; close.push([data[i][0], data[i][1]]); if (data[i][1]*1 > 0) min_last = Math.min(min_last, data[i][1]); max_last = Math.max(max_last, data[i][1]); } if (min_last == max_last) min_last = 0; //console.log(min_last+"!"+max_last+"!"+(max_last*1 == fdata.lastc*1)+"#"+(min_last*1 == fdata.lastc*1)); var self = this; return { chart:{ spacing: [0, 0, 0, 0], marginRight: 48, marginLeft: 0, marginTop: 0, marginBottom: 44, backgroundColor: null }, tooltip: { shadow: false, useHTML: true, padding: 0, borderWidth: 0, backgroundColor: "none", formatter: function() { var yval = (this.points[0].y >= 1000)? addcomma(this.points[0].y.toFixed(0)):this.points[0].y; var ypos = this.points[0].point.plotY; var xval = this.points[0].x; var xpos = this.points[0].point.plotX; var arr = new Array(); arr['x'] = new Array(xval, xpos); arr['y'] = new Array(yval, ypos); self.drawTooltip(arr); } //enabled: false }, rangeSelector: { enabled: false }, xAxis: { tickLength:0, gridLineWidth: 0, lineWidth: 0, align: "top", opposite: false, labels: { y : 17, formatter : function() { /*var val = Highcharts.dateFormat('%H', this.value); var val2 = Highcharts.dateFormat('%M', this.value); if(val != '9') { //if(val != '13' || (val == '13' && self.ucode != 'hsi' && self.ucode != 'cei' && self.ucode != 'zzzf' && ucurrency == 'SGD')) { return val+':00'; //} }*/ return Highcharts.dateFormat('%H:00', this.value); }, style: { color: self.colors['label'], fontSize: '11px' } }, tickPositioner: function () { var positions = []; var lastday = 0; var msec; msec = 60*60*1000*2; lastday = Math.floor(close[0][0]/msec)*msec; for (i=0;i 1000) ? this.value.toFixed(0) : this.value; return (this.isLast)?"":addcomma(this.value); }, style: { color: self.colors['label'], fontSize: '11px' } }, top:0, offset:0, tickPixelInterval:40, tickAmount : 6, showFirstLabel: false, showLastLabel: true, gridLineWidth: 0, lineWidth: 0, opposite: true, max: (max_last*1 == fdata.lastc*1) ? max_last : null, min: (min_last*1 == fdata.lastc*1) ? min_last : null, plotLines: [{ value: fdata.lastc, color: self.colors["lastc"], dashStyle: "Solid", width: 1, zIndex: 1, }] }], navigator : { enabled : false }, scrollbar : { enabled : false }, series : [{ name : "last", data : close, lineWidth: 1.5, color: self.colors["line"], }], exporting: { enabled: false }, credits: { enabled: false }, }; }, drawBackground: function(){ var chart = this.chart; var offsetx,offsety; offsetx = 1; offsety = chart.chartHeight - 2; var txt = (lang=="en") ? "Last Close" : "내재가치"; var fontstyle = {color: this.colors['grey'], fontSize: '12.5px', 'font-weight': 'bold'}; chart.renderer.text(txt, offsetx, offsety).css(fontstyle).add(); offsetx = (lang=='en') ? 80 : 55; offsety = offsety - 5; chart.renderer.rect(offsetx, offsety, 15, 2).attr({ fill: this.colors["lastc"] }).add(); offsetx = 0; offsety = chart.chartHeight - chart.marginBottom + 2; chart.renderer.rect(offsetx, offsety, chart.chartWidth, 1).attr({ fill: this.colors["drawLine"] }).add(); offsetx = 120; offsety = chart.chartHeight - 2; var txt = (lang=="en") ? "Last Price" : "현재가"; var fontstyle = {color: this.colors['grey'], fontSize: '12.5px', 'font-weight': 'bold'}; chart.renderer.text(txt, offsetx, offsety).css(fontstyle).add(); offsetx = (lang=='en') ? 200 : 165; offsety = offsety - 5; chart.renderer.rect(offsetx, offsety, 15, 2).attr({ fill: this.colors["line"] }).add(); }, drawTooltip: function(arr){ //arr[x, y] => arr[val, pos] var chart = this.chart; var fontstyle = {color: '#fff', fontSize: '11px'}; var textattr = {zIndex: 7, class: "tooltipElement"}; $(".highcharts-axis-labels text").removeAttr("class", "tooltipElement"); $(".tooltipElement").remove(); //console.log(arr); //yAxis last y_posY = arr['y'][1]-7; y_posX = chart.chartWidth - chart.marginRight; chart.renderer.rect(y_posX, y_posY, chart.marginRight, 15, 0).attr({ fill: this.colors["yTooltip"], 'stroke-width': 0, 'zIndex':7, class: 'tooltipElement' }).add(); //chart.renderer.text(arr['y1'][0], y_posX+5, (y_posY+11.5)).css(fontstyle).attr(textattr).add(); lastLabel = chart.renderer.label(arr['y'][0], y_posX, (y_posY-3)).css(fontstyle).attr(textattr).add(); lastLabel.attr({ x: chart.chartWidth - lastLabel.width }); //xAxis time x_posX = arr['x'][1]-19; x_posY = chart.chartHeight - chart.marginBottom + 5; var format = '%H:%M'; var w = 38; if(x_posX < 0) { x_posX = 0; } chart.renderer.rect(x_posX, x_posY, w, 15, 0).attr({ fill: this.colors["xTooltip"], 'stroke-width': 0, 'zIndex':7, class: 'tooltipElement' }).add(); chart.renderer.text(Highcharts.dateFormat(format, arr['x'][0]), x_posX+3, (x_posY+12)).css(fontstyle).attr(textattr).add(); } }