考虑以下代码
xaxis: {
min: Min,
max:Max,
ticks: Ticks,
renderer:$.jqplot.DateAxisRenderer,
},
像这样设置xaxis后,缩放功能对xaxis不起作用,如何在不删除“ticks:Ticks”行的情况下解决问题?
答案 0 :(得分:1)
解决方案(将其添加到您的javascript文件中):
$.jqplot.LinearAxisRenderer.prototype.createTicks=function(b){var c=this.ticks,e=this.name,a=this._dataBounds,g="x"===this.name.charAt(0)?this._plotDimensions.width:this._plotDimensions.height,f;f=this.min;var k=this.max,d=this.numberTicks,h=this.tickInterval;this._scalefact=(Math.max(g,31)-30)/300;if(c.length){for(e=0;e<c.length;e++)h=c[e],h[0]>f&&h[0]<k&&(d=new this.tickRenderer(this.tickOptions),$.isArray(h)?(d.value=h[0],this.breakPoints?h[0]==this.breakPoints[0]?(d.label=this.breakTickLabel, d._breakTick=!0,d.showGridline=!1,d.showMark=!1):(h[0]>this.breakPoints[0]&&h[0]<=this.breakPoints[1]&&(d.show=!1,d.showGridline=!1),d.label=h[1]):d.label=h[1],d.setTick(h[0],this.name)):$.isPlainObject(h)?($.extend(!0,d,h),d.axis=this.name):(d.value=h,this.breakPoints&&(h==this.breakPoints[0]?(d.label=this.breakTickLabel,d._breakTick=!0,d.showGridline=!1,d.showMark=!1):h>this.breakPoints[0]&&h<=this.breakPoints[1]&&(d.show=!1,d.showGridline=!1)),d.setTick(h,this.name)),this._ticks.push(d));this.numberTicks= c.length;this.min=f;this.max=k;this.tickInterval=(this.max-this.min)/(this.numberTicks-1)}else{g="xaxis"==e||"x2axis"==e?this._plotDimensions.width:this._plotDimensions.height;e=this.numberTicks;this.alignTicks&&("x2axis"===this.name&&b.axes.xaxis.show?e=b.axes.xaxis.numberTicks:"y"===this.name.charAt(0)&&"yaxis"!==this.name&&"yMidAxis"!==this.name&&b.axes.yaxis.show&&(e=b.axes.yaxis.numberTicks));c=null!=this.min?this.min:a.min;b=null!=this.max?this.max:a.max;a=b-c;null!=this.tickOptions&&this.tickOptions.formatString|| (this._overrideFormatString=!0);if(null==this.min||null==this.max&&null==this.tickInterval&&!this.autoscale){this.forceTickAt0&&(0<c&&(c=0),0>b&&(b=0));this.forceTickAt100&&(100<c&&(c=100),100>b&&(b=100));k=f=!1;null!=this.min?f=!0:null!=this.max&&(k=!0);d=$.jqplot.LinearTickGenerator(c,b,this._scalefact,e,f,k);h=null!=this.min?c:c+a*(this.padMin-1);g=null!=this.max?b:b-a*(this.padMax-1);if(c<h||b>g)h=null!=this.min?c:c-a*(this.padMin-1),g=null!=this.max?b:b+a*(this.padMax-1),d=$.jqplot.LinearTickGenerator(h, g,this._scalefact,e,f,k);this.min=d[0];this.max=d[1];this.numberTicks=d[2];this._autoFormatString=d[3];this.tickInterval=d[4]}else{c==b&&(e=0.05,0<c&&(e=Math.max(Math.log(c)/Math.LN10,0.05)),c-=e,b+=e);if(this.autoscale&&null==this.min&&null==this.max){for(var p=!1,s=!1,e=0;e<this._series.length;e++){var l=this._series[e];if(this.name==("x"==l.fillAxis?l._xaxis.name:l._yaxis.name)){for(var q=l._plotValues[l.fillAxis],n=q[0],r=q[0],m=1;m<q.length;m++)q[m]<n?n=q[m]:q[m]>r&&(r=q[m]);m=(r-n)/r;l.renderer.constructor== $.jqplot.BarRenderer?0<=n&&(l.fillToZero||0.1<m)?p=!0:(p=!1,s=l.fill&&l.fillToZero&&0>n&&0<r?!0:!1):l.fill?0<=n&&(l.fillToZero||0.1<m)?p=!0:0>n&&0<r&&l.fillToZero?(p=!1,s=!0):s=p=!1:0>n&&(p=!1)}}p?(this.numberTicks=2+Math.ceil((g-(this.tickSpacing-1))/this.tickSpacing),f=this.min=0,g=b/(this.numberTicks-1),b=Math.pow(10,Math.abs(Math.floor(Math.log(g)/Math.LN10))),g/b==parseInt(g/b,10)&&(g+=b),this.tickInterval=Math.ceil(g/b)*b,this.max=this.tickInterval*(this.numberTicks-1)):s?(this.numberTicks= 2+Math.ceil((g-(this.tickSpacing-1))/this.tickSpacing),a=Math.ceil(Math.abs(c)/a*(this.numberTicks-1)),e=this.numberTicks-1-a,g=Math.max(Math.abs(c/a),Math.abs(b/e)),b=Math.pow(10,Math.abs(Math.floor(Math.log(g)/Math.LN10))),this.tickInterval=Math.ceil(g/b)*b,this.max=this.tickInterval*e,this.min=-this.tickInterval*a):(null==this.numberTicks&&(this.numberTicks=this.tickInterval?3+Math.ceil(a/this.tickInterval):2+Math.ceil((g-(this.tickSpacing-1))/this.tickSpacing)),null==this.tickInterval?(g=a/(this.numberTicks- 1),b=1>g?Math.pow(10,Math.abs(Math.floor(Math.log(g)/Math.LN10))):1,this.tickInterval=Math.ceil(g*b*this.pad)/b):b=1/this.tickInterval,g=this.tickInterval*(this.numberTicks-1),a=(g-a)/2,null==this.min&&(this.min=Math.floor(b*(c-a))/b),null==this.max&&(this.max=this.min+g));a=$.jqplot.getSignificantFigures(this.tickInterval);a.digitsLeft>=a.significantDigits?a="%d":(b=Math.max(0,5-a.digitsLeft),b=Math.min(b,a.digitsRight),a="%."+b+"f");this._autoFormatString=a}else c=null!=this.min?this.min:c-a*(this.padMin- 1),e=null!=this.max?this.max:b+a*(this.padMax-1),a=e-c,null==this.numberTicks&&(this.numberTicks=null!=this.tickInterval?Math.ceil((e-c)/this.tickInterval)+1:100<g?parseInt(3+(g-100)/75,10):2),null==this.tickInterval&&(this.tickInterval=a/(this.numberTicks-1)),null==this.max&&(e=c+this.tickInterval*(this.numberTicks-1)),null==this.min&&(c=e-this.tickInterval*(this.numberTicks-1)),a=$.jqplot.getSignificantFigures(this.tickInterval),a.digitsLeft>=a.significantDigits?a="%d":(b=Math.max(0,5-a.digitsLeft), b=Math.min(b,a.digitsRight),a="%."+b+"f"),this._autoFormatString=a,this.min=c,this.max=e;this.renderer.constructor==$.jqplot.LinearAxisRenderer&&""==this._autoFormatString&&(a=(new this.tickRenderer(this.tickOptions)).formatString||$.jqplot.config.defaultTickFormatString,a=a.match($.jqplot.sprintf.regex)[0],c=0,a&&(-1<a.search(/[fFeEgGpP]/)?c=(c=a.match(/\%\.(\d{0,})?[eEfFgGpP]/))?parseInt(c[1],10):6:-1<a.search(/[di]/)&&(c=0),a=Math.pow(10,-c),this.tickInterval<a&&null==d&&null==h&&(this.tickInterval= a,null==k&&null==f?(this.min=Math.floor(this._dataBounds.min/a)*a,this.min==this._dataBounds.min&&(this.min=this._dataBounds.min-this.tickInterval),this.max=Math.ceil(this._dataBounds.max/a)*a,this.max==this._dataBounds.max&&(this.max=this._dataBounds.max+this.tickInterval),f=(this.max-this.min)/this.tickInterval,f=f.toFixed(11),f=Math.ceil(f),this.numberTicks=f+1):null==k?(f=(this._dataBounds.max-this.min)/this.tickInterval,f=f.toFixed(11),this.numberTicks=Math.ceil(f)+2,this.max=this.min+this.tickInterval* (this.numberTicks-1)):null==f?(f=(this.max-this._dataBounds.min)/this.tickInterval,f=f.toFixed(11),this.numberTicks=Math.ceil(f)+2,this.min=this.max-this.tickInterval*(this.numberTicks-1)):(this.numberTicks=Math.ceil((k-f)/this.tickInterval)+1,this.min=Math.floor(f*Math.pow(10,c))/Math.pow(10,c),this.max=Math.ceil(k*Math.pow(10,c))/Math.pow(10,c),this.numberTicks=Math.ceil((this.max-this.min)/this.tickInterval)+1))))}this._overrideFormatString&&""!=this._autoFormatString&&(this.tickOptions=this.tickOptions|| {},this.tickOptions.formatString=this._autoFormatString);for(e=0;e<this.numberTicks;e++)if(f=this.min+e*this.tickInterval,d=new this.tickRenderer(this.tickOptions),d.setTick(f,this.name),this._ticks.push(d),e<this.numberTicks-1)for(m=0;m<this.minorTicks;m++)f+=this.tickInterval/(this.minorTicks+1),k=$.extend(!0,{},this.tickOptions,{name:this.name,value:f,label:"",isMinorTick:!0}),d=new this.tickRenderer(k),this._ticks.push(d)}this.tickInset&&(this.min-=this.tickInset*this.tickInterval,this.max+=this.tickInset* this.tickInterval)};
<强> Desription:强>
嗨,
我知道你之前问了一段时间,但我也需要解决方案,所以我通过jqplot代码并覆盖一个函数。此函数创建刻度线,如果您的刻度线位于“缩放窗口”,我只需添加一些比较
这条线很长,看起来不太漂亮我知道但不幸的是这个函数有超过500行,所以我认为compilation是更好的解决方案。
如果有人想我可以粘贴整个未编译的功能。