var _this = this; var $container = $(this.container); var $yAxis = _this.data.yAxis; var $yAxis2 = _this.data.yAxis2; var $svgBox = $container.find(".sfc-wk-major-salary-chart-wrapper"); var $svg = $container.find(".sfc-wk-major-salary-svg"); var $yPos = $container.find(".sfc-wk-major-salary-svg-yAxis-item1"); var $xAxis = $container.find(".sfc-wk-major-salary-svg-xAxis"); var num = $yAxis.length; var $svgWidth = Math.ceil($svgBox.width());
/* 起点高度 */ var $svgheight = 180; var start = $svgheight; var maxPos = 20; var minPos = start, yAxis = start, prevY = start; var xAxis = 0, prevX = 0; var cx = [], cy = [], maxY = [];
/* 将yAxis和yAxis2存入maxY中 */ var allNum = num + $yAxis2.length; var allAxis = $yAxis.concat($yAxis2); for(var j=0;j<allNum; j++){ maxY[j] = parseFloat(allAxis[j].y); };
/* 找到yAxis和yAxis2中的最大值和最小值 */ var max = maxY[0]; var min = maxY[0]; for(var k=0;k<maxY.length; k++){ if(max < maxY[k]){ max = maxY[k] }; if(min > maxY[k]){ min = maxY[k] }; };
/* 最大值和最小值以1000为单位分别向上向下取整 */ max = Math.ceil(max / 1000) * 1000; min = Math.floor(min / 1000) * 1000;
/* 计算刻度 */ var posChazhi = minPos-maxPos; var percentChazhi = max-min; var bili = posChazhi/percentChazhi;
/* 绘制虚线 每间隔1000绘制一条*/ var lineNum = (max - min) / 1000; var $lineWrapper = $container.find(".sfc-wk-major-salary-svg-line"); var lineH = posChazhi / (lineNum) - 1; var html = '<div class="sfc-wk-major-salary-svg-line-item" style="height: ' + maxPos + 'px;"><span style="position:absolute;top: 0px;">' + max + '</span></div>';; for (var n = 0;n < lineNum;n++) { html += '<div class="sfc-wk-major-salary-svg-line-item" style="height:' + lineH + 'px;"><span style="position:absolute;top:' + (lineH - 20) + 'px;">' + (max - (n + 1) * 1000) + '</span></div>'; } $lineWrapper.html(html);
functionSVG1(){ var jianju = Math.round($svgWidth/num); var first = Math.round(jianju/2); $xAxis.attr("d","M 0 "+ $svgheight +" L "+ $svgWidth +" "+$svgheight); for(var i=0; i<num; i++){ var yVal = parseFloat($yAxis[i].y); var round = Math.round((yVal-min)*bili); yAxis = start-round; if(i==0){ xAxis = first; /* $svgBox.find(".sfc-wk-major-salary-svg-yItem1").eq(i).attr("d","M 0 "+start+" L "+xAxis+" "+yAxis); */ $svgBox.find(".sfc-wk-major-salary-svg-yPos1").eq(i).attr({"cx":xAxis,"cy":yAxis}); $yPos.eq(i).css({"top":(yAxis-20)+"px","left":(xAxis-15)+"px"}); cx[i] = xAxis; cy[i] = yAxis; }else{ var yVal1 = parseFloat($yAxis[i-1].y); var round1 = Math.round((yVal1-min)*bili); prevY = start-round1; xAxis = first + jianju*[i]; prevX = first + jianju*([i]-1); $svgBox.find(".sfc-wk-major-salary-svg-yItem1").eq(i).attr("d","M "+prevX+" "+prevY+" L "+xAxis+" "+yAxis); $svgBox.find(".sfc-wk-major-salary-svg-yPos1").eq(i).attr({"cx":xAxis,"cy":yAxis}); $yPos.eq(i).css({"top":(yAxis-20)+"px","left":(xAxis-16)+"px"}); cx[i] = xAxis; cy[i] = yAxis; } }; var xlast = $svgBox.find(".sfc-wk-major-salary-svg-yPos1").eq(num-1).attr('cx'); var ylast = $svgBox.find(".sfc-wk-major-salary-svg-yPos1").eq(num-1).attr('cy');