Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带morris.js的对数轴_Javascript_Linechart_Logarithm_Morris.js - Fatal编程技术网

Javascript 带morris.js的对数轴

Javascript 带morris.js的对数轴,javascript,linechart,logarithm,morris.js,Javascript,Linechart,Logarithm,Morris.js,我试图得到morris.js折线图y轴的对数刻度 我已经尝试过使用yLabelFormat选项,但这不是我需要的。 任何暗示都将不胜感激 如果morris.js无法做到这一点,您可以建议使用另一个轻量级javascript库来制作具有对数刻度的简单折线图 您可以扩展Morris并修改transY函数以进行对数刻度 我还添加了gridIntegers参数,使得y轴上只有整数 如果只需要yLogScale,请删除transY功能后的代码 使用以下代码段查看yLogScale参数设置为true或fa

我试图得到morris.js折线图y轴的对数刻度

我已经尝试过使用yLabelFormat选项,但这不是我需要的。 任何暗示都将不胜感激


如果morris.js无法做到这一点,您可以建议使用另一个轻量级javascript库来制作具有对数刻度的简单折线图

您可以扩展Morris并修改
transY
函数以进行对数刻度

我还添加了
gridIntegers
参数,使得y轴上只有整数

如果只需要
yLogScale
,请删除
transY
功能后的代码

使用以下代码段查看
yLogScale
参数设置为
true
false
的结果

(函数(){
var$,MyMorris;
MyMorris=window.MyMorris={};
$=jQuery;
MyMorris=Object.create(Morris);
MyMorris.Grid.prototype.gridDefaults[“yLogScale”]=false;
MyMorris.Grid.prototype.gridDefaults[“gridIntegers”]=false;
MyMorris.Grid.prototype.transY=函数(y){
如果(!this.options.horizontal){
if(this.options.yLogScale){
返回this.bottom-(this.height*Math.log((y+1)-this.ymin)/Math.log(this.ymax/(this.ymin+1));
}否则{
返回this.bottom-(y-this.ymin)*this.dy;
}
}否则{
返回this.left+(y-this.ymin)*this.dy;
}
};
MyMorris.Grid.prototype.setData=函数(数据,重绘){
变量e、idx、指数、最大目标、最小目标、ret、行、步长、总计、y、ykey、ymax、ymin、yval、_ref;
如果(重画==null){
重画=真;
}
this.options.data=数据;
if((data==null)| | data.length==0){
这个.data=[];
这个。拉斐尔。克利尔();
如果(this.hover!=null){
this.hover.hide();
}
返回;
}
ymax=this.cumulative?0:null;
ymin=this.cumulative?0:null;
如果(this.options.goals.length>0){
minGoal=Math.min.apply(Math,this.options.goals);
maxGoal=Math.max.apply(Math,this.options.goals);
ymin=ymin!=null?Math.min(ymin,minGoal):minGoal;
ymax=ymax!=null?Math.max(ymax,maxGoal):maxGoal;
}
this.data=(函数(){
变量i,len,结果;
_结果=[];
对于(索引=_i=0,_len=data.length;_i<_len;索引=++_i){
行=数据[索引];
ret={
src:row
};
ret.label=行[this.options.xkey];
if(this.options.parseTime){
ret.x=Morris.parseDate(ret.label);
if(this.options.dateFormat){
ret.label=this.options.dateFormat(ret.x);
}else if(ret.label的类型=='number'){
ret.label=新日期(ret.label).toString();
}
}否则{
ret.x=指数;
if(this.options.xLabelFormat){
ret.label=this.options.xLabelFormat(ret);
}
}
总数=0;
ret.y=(函数(){
变量j,变量len1,变量ref,变量results1;
_ref=this.options.ykeys;
_结果1=[];
对于(idx=_j=0,_len1=_ref.length;_j<_len1;idx=++_j){
ykey=_ref[idx];
yval=行[ykey];
如果(yval的类型=='string'){
yval=解析浮点(yval);
}
if((yval!=null)&&typeof yval!=“number”){
yval=null;
}
如果(yval!=null){
如果(这是累积的){
总+=yval;
}否则{
如果(ymax!=null){
ymax=数学最大值(yval,ymax);
ymin=数学最小值(yval,ymin);
}否则{
ymax=ymin=yval;
}
}
}
if(this.cumulative&&(total!=null)){
ymax=数学最大值(总计,ymax);
ymin=数学最小值(总计,ymin);
}
_结果1.推挤(yval);
}
返回结果1;
}).打电话(这个);
_结果:推挤(ret);
}
返回结果;
}).打电话(这个);
if(this.options.parseTime){
this.data=this.data.sort(函数(a,b){
返回(a.x>b.x)-(b.x>a.x);
});
}
this.xmin=this.data[0].x;
this.xmax=this.data[this.data.length-1].x;
this.events=[];
如果(this.options.events.length>0){
if(this.options.parseTime){
this.events=(函数(){
变量i,len,ref,结果;
_ref=this.options.events;
_结果=[];
对于(_i=0,_len=_ref.length;_i<_len;_i++){
e=_ref[_i];
_结果:push(Morris.parseDate(e));
}
返回结果;
}).打电话(这个);
}否则{
this.events=this.options.events;
}
this.xmax=Math.max(this.xmax,Math.max.apply