var warrantCalChart={container:"",chart:null,ulast:"",ulast_starting:"",wlast:"",fix_wlast:"",init:function(ulast,ulast_starting,callback){var self=this;self.labels["edu"]=self.labels["th"];var data=getChartdata();data=self.decode(data,ulast,ulast_starting);$((self.container=='')?'#warrantCalChartContainer':'#'+self.container).highcharts('StockChart',self.getJSON(data,ulast,ulast_starting),function(chart){self.chart=chart;self.ulast=ulast;self.ulast_starting=ulast_starting;self.wlast=data[0].wlast;self.fix_wlast=data[0].fix_wlast;self.drawBackground(ulast,ulast_starting,[self.wlast,self.fix_wlast]);if(callback!==undefined){callback(chart,data)}})},decode:function(_data,c_ulast,c_ulast_starting){for(var i=0;i<_data[0].code1.length;i++){if(isNaN(_data[0].code1[i][1])){_data[0].code1[i][1]=0}if(_data[0].code1[i][1]<0){_data[0].code1[i][1]=0}}for(var i=0;i<_data[0].code2.length;i++){if(isNaN(_data[0].code2[i][1])){_data[0].code2[i][1]=0}if(_data[0].code2[i][1]<0){_data[0].code2[i][1]=0}}return _data},colors:{yaxis:"#ed8b00",line:"#ed8b00",gridline:'#E2E4E5',tooltip:"#ed8b00",black:"#000000",blue:"#8BA9D3",current_price:"#1a7b99"},getJSON:function(_data,ulast,ulast_starting){var self=this;var data1=_data[0];return{chart:{spacing:[0,0,0,0],marginLeft:0,marginRight:0,marginTop:20,marginBottom:0,events:{redraw:function(event){self.drawBackground(self.ulast,self.ulast_starting,[self.wlast,self.fix_wlast])}}},tooltip:{backgroundColor:"none",borderWidth:0,shadow:false,useHTML:true,shape:"square",shared:true,padding:0,formatter:function(){self.drawYaxisTooltip(this)},},rangeSelector:{enabled:false,},xAxis:{tickLength:10,gridLineWidth:0,gridZIndex:-1,lineWidth:0,align:"bottom",opposite:false,tickPositions:xAxis,crosshair:false,events:{setExtremes:function(e){if(typeof(e.rangeSelectorButton)!=='undefined'){if(e.rangeSelectorButton.type=="all"){}else{}}}},labels:{y:-25,formatter:function(){val=this.value;return''+val+''},style:{color:''}},title:{x:-5,y:-3,text:self.labels[lang].xtitle,rotation:0},plotLines:[{id:"underlying_line",color:self.colors["line"],width:2,value:ulast,zIndex:5},]},yAxis:[{labels:{align:'left',x:0,y:14,tickLength:10,formatter:function(){return''+this.value+''},style:{color:self.colors["yaxis"]}},top:20,offset:0,height:360,tickPixelInterval:70,showLastLabel:true,showFirstLabel:false,gridLineColor:self.colors["gridline"],zIndex:99,lineWidth:1,lineColor:self.colors["gridline"],opposite:false,crosshair:false,}],navigator:{enabled:false},scrollbar:{enabled:false},series:[{name:'code2',data:data1.code2,lineWidth:2,color:self.colors["line"],zIndex:10,animation:false,dataGrouping:{enabled:false}},{name:'code1',data:data1.code1,lineWidth:2,color:'#1a7b99',zIndex:8,animation:false,dataGrouping:{enabled:false}}],exporting:{enabled:false},credits:{enabled:false},}},drawBackground:function(ulast,ulast_starting,wlast){var chart=this.chart;var offsetx,offsety;chart.renderer.path(['M',0,380.5,'L',chart.plotWidth+65,380.5]).attr({id:"intra_chart_path1",'stroke-width':1,opacity:1,stroke:'#000000',zIndex:1,class:"intra_chart_path",}).add();val=ulast_starting*1;val_length=val.toString().length;w_label=val_length*10;fontstyle2={color:'#fff',fontSize:'11px'};upos=chart.xAxis[0].toPixels(val);offsetx=upos-(w_label/2);if(offsetx<0){offsetx=0}else if(offsetx+w_label>chart.chartWidth){offsetx=chart.chartWidth-w_label}offsety=361+20;$("#w_labelRect").remove();chart.renderer.rect(offsetx,offsety,w_label,17,0).attr({fill:'#1a7b99','stroke-width':0,'zIndex':8,id:'w_labelRect'}).add();$("#w_labelText").remove();chart.renderer.text(val,offsetx+val_length,offsety+12.5).css(fontstyle2).attr({zIndex:8,id:'w_labelText'}).add();ypos=chart.yAxis[0].toPixels(wlast[1]);$(".classRect").remove();chart.renderer.rect(upos-1,19.5,2,offsety-2.5,0).attr({fill:'#1a7b99','stroke-width':0,'zIndex':4,class:"classRect"}).add();val=ulast;val_length=val.toString().length;w_label=val_length*10;uplotline=chart.xAxis[0].plotLinesAndBands[0];upos=chart.xAxis[0].toPixels(uplotline.options.value);offsetx=upos-(w_label/2);if(offsetx<0){offsetx=0}else if(offsetx+w_label>chart.chartWidth){offsetx=chart.chartWidth-w_label}offsety=20;$("#w_labelRect2").remove();chart.renderer.rect(offsetx,offsety,w_label,17,0).attr({fill:this.colors["line"],'stroke-width':0,'zIndex':6,id:'w_labelRect2'}).add();$("#w_label2").remove();textattr={zIndex:7,id:'w_label2'};chart.renderer.text(val,offsetx+val_length,offsety+12.5).css(fontstyle2).attr(textattr).add();fontstyle={color:'#fff',fontSize:'12px'};var w_val=wlast[0];w_val=(w_val==undefined)?0:w_val;var wlast_pos=chart.yAxis[0].toPixels(w_val);wlast_pos-=10;chart.renderer.rect(0,wlast_pos,48,20,0).attr({fill:this.colors["yaxis"],'stroke-width':0,'zIndex':5,class:'ytooltipElement'}).add();chart.renderer.text((w_val).toFixed(_spreadTable(w_val)),9,wlast_pos+14).css(fontstyle).attr({zIndex:7,class:'ytooltipElement'}).add();chart.renderer.rect(0,wlast_pos+9,chart.chartWidth-5,2,0).attr({fill:this.colors["yaxis"],'stroke-width':0,'zIndex':5,class:'ytooltipElement'}).add();fontstyle={color:'#fff',fontSize:'12px'};var w_val=wlast[1];w_val=(w_val==undefined)?0:w_val;var wlast_pos=chart.yAxis[0].toPixels(w_val);wlast_pos-=10;$(".wlast_posRect").remove();chart.renderer.rect(0,wlast_pos,48,20,0).attr({fill:'#1a7b99','stroke-width':0,'zIndex':7,class:'wlast_posRect'}).add();$(".wlast_pos").remove();chart.renderer.text((w_val).toFixed(_spreadTable(w_val)),9,wlast_pos+14).css(fontstyle).attr({zIndex:7,class:'wlast_pos'}).add();$(".wlastLine").remove();chart.renderer.rect(0,wlast_pos+9,chart.chartWidth-5,2,0).attr({fill:'#1a7b99','stroke-width':0,'zIndex':0,class:'wlastLine'}).add()},drawYaxisTooltip:function(datas){var yval=datas.points[0].y;yval=yval.toFixed(_spreadTable(yval))*1;var ypos=datas.points[0].point.plotY;var yval2=datas.points[1].y;yval2=yval2.toFixed(_spreadTable(yval2))*1;var ypos2=datas.points[1].point.plotY;var chart=this.chart;var fontstyle={color:'#fff',fontSize:'12px'};var textattr={zIndex:8,class:"ytooltipElement"};var textattr2={zIndex:7,class:"ytooltipElement"};$(".highcharts-axis-labels text").removeAttr("class","ytooltipElement");$(".ytooltipElement").remove();$(".highcharts-axis-labels text").removeAttr("class","ytooltipElemen2t");$(".ytooltipElement2").remove();var pos=ypos+(20/2);var pos2=ypos2+(20/2);chart.renderer.rect(0,pos,48,20,0).attr({fill:this.colors["line"],'stroke-width':0,'zIndex':8,class:'ytooltipElement'}).add();$(".wlastLine").remove();chart.renderer.rect(0,pos+9,chart.chartWidth-5,2,0).attr({fill:this.colors["line"],'stroke-width':0,'zIndex':1,class:'wlastLine'}).add();chart.renderer.text(yval,9,pos+14).css(fontstyle).attr(textattr).add();chart.renderer.rect(0,pos2,48,20,0).attr({fill:this.colors["current_price"],'stroke-width':0,'zIndex':7,class:'ytooltipElement2'}).add();$(".wlastLine2, .wlast_posRect, .wlast_pos").remove();chart.renderer.rect(0,pos2+9,chart.chartWidth-5,2,0).attr({fill:this.colors["current_price"],'stroke-width':0,'zIndex':0,class:'wlastLine2'}).add();chart.renderer.text(yval2,9,pos2+14).css(fontstyle).attr(textattr2).add()},labels:{th:{xtitle:'ราคาหลักทรัพย์อ้างอิง',ytitle1:'ราคาปัจจุบัน',ytitle2:'ราคาจากการคำนวณ'},en:{xtitle:'Underlying Price',ytitle1:'Current price',ytitle2:'Simulated price'}}}