var warrantCalChart={container:"",chart:null,ulast:"",wlast:"",fix_wlast:"",init:function(ulast,callback){var self=this;self.labels["edu"]=self.labels["th"];var data=getChartdata();data=self.decode(data,ulast);$((self.container=='')?'#warrantCalChartContainer':'#'+self.container).highcharts('StockChart',self.getJSON(data,ulast),function(chart){self.chart=chart;self.ulast=ulast;self.wlast=data[0].wlast;self.fix_wlast=data[0].fix_wlast;self.drawBackground(ulast,[data[0].wlast,data[0].fix_wlast]);if(callback!==undefined){callback(chart,data)}})},decode:function(_data,_ulast){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}if(_data[0].code2[i][0]==_ulast){_data[0].wlast=_data[0].code2[i][1];if(_data[0].wlast!=null){_data[0].wlast=_data[0].wlast.toFixed(_spreadTable(_data[0].wlast))*1}}}return _data},colors:{yaxis:"#ed8b00",line:"#ed8b00",gridline:'#E2E4E5',tooltip:"#ed8b00",black:"#000000",blue:"#8BA9D3"},getJSON:function(_data,ulast){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.wlast,self.fix_wlast])}}},tooltip:{backgroundColor:"none",borderWidth:0,shadow:false,useHTML:true,shape:"square",padding:0,formatter:function(){var yval=this.points[0].y;var ypos=this.points[0].point.plotY;self.drawYaxisTooltip(yval.toFixed(_spreadTable(yval))*1,ypos)},},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:340,tickPixelInterval:70,showLastLabel:true,showFirstLabel:false,gridLineColor:self.colors["gridline"],zIndex:99,lineWidth:1,lineColor:self.colors["gridline"],opposite:false,crosshair:{color:self.colors["yaxis"],className:'chart_crosshair',width:2,},}],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,enableMouseTracking:false,dataGrouping:{enabled:false}}],exporting:{enabled:false},credits:{enabled:false},}},drawBackground:function(ulast,wlast){var chart=this.chart;var offsetx,offsety;chart.renderer.path(['M',0,360.5,'L',chart.plotWidth+65,360.5]).attr({id:"intra_chart_path1",'stroke-width':1,opacity:1,stroke:'#000000',zIndex:1,class:"intra_chart_path",}).add();val=_ulast*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;$("#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,ypos,2,360-ypos,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,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,id:'wlast_posRect'}).add();$(".wlast_pos").remove();chart.renderer.text(w_val,9,wlast_pos+14).css(fontstyle).attr({zIndex:7,id:'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(yval,ypos){var chart=this.chart;var fontstyle={color:'#fff',fontSize:'12px'};var textattr={zIndex:7,class:"ytooltipElement"};$(".highcharts-axis-labels text").removeAttr("class","ytooltipElement");$(".ytooltipElement").remove();var pos=ypos+(20/2);chart.renderer.rect(0,pos,48,20,0).attr({fill:this.colors["yaxis"],'stroke-width':0,'zIndex':7,class:'ytooltipElement'}).add();chart.renderer.text(yval,9,pos+14).css(fontstyle).attr(textattr).add()},labels:{th:{xtitle:'ราคาหลักทรัพย์อ้างอิง',ytitle1:'ราคาปัจจุบัน',ytitle2:'ราคาจากการคำนวณ'},en:{xtitle:'Underlying Price',ytitle1:'Current price',ytitle2:'Simulated price'}}}