Javascript 从MyRIS.JS线图中删除额外的X轴线

Javascript 从MyRIS.JS线图中删除额外的X轴线,javascript,morris.js,Javascript,Morris.js,我试图使用morris.js创建一个折线图,但该图显示了带有浮点值的额外线条。但我只需要图表显示0和1轴 这是我的图形配置 config = { data: graphData, xkey: 'x', ykeys: ['a','b'], parseTime: false, fillOpacity: 0.6, hideHover: 'auto', behaveLikeLine: true, resize: false, po

我试图使用morris.js创建一个折线图,但该图显示了带有浮点值的额外线条。但我只需要图表显示0和1轴

这是我的图形配置

config = {
    data: graphData,
    xkey: 'x',
    ykeys: ['a','b'],
    parseTime: false,
    fillOpacity: 0.6,
    hideHover: 'auto',
    behaveLikeLine: true,
    resize: false,
    pointFillColors:['#ffffff'],
    pointStrokeColors: ['black'],
    lineColors:['red','orange'],
    hoverCallback: function(index, options, content, row) {
      return(content);
    },
    gridIntegers: true,
    ymax: 1,
    ymin: 0,

  };
config.element = 'line-chart';

$("#line-chart").empty();

Morris.Line(config);
我只为x轴提交1和0

[
    {
        "x": "2020-02-15 06:36:21",
        "a": 1,
        "b": 1
    },
    {
        "x": "2020-02-14 21:35:37",
        "a": 0,
        "b": 0
    }
]

Morris的官方最新版本没有
gridIntegers
参数。它是在pull请求中添加的,并在Morris的中提供

您还可以使用Morris的最新官方版本,并对其进行扩展以添加此参数,就像在我的代码片段中一样。然后,将此参数设置为
true
,就像您尝试的那样,应该可以正常工作

请尝试以下代码段:

(函数(){
var$,MyMorris;
MyMorris=window.MyMorris={};
$=jQuery;
MyMorris=Object.create(Morris);
MyMorris.Grid.prototype.gridDefaults[“gridIntegers”]=false;
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(Math,this.events));
this.xmin=Math.min(this.xmin,Math.min.apply(Math,this.events));
}
if(this.xmin==this.xmax){
这是0.xmin-=1;
这个值为0.xmax+=1;
}
this.ymin=this.yboundary('min',ymin);
this.ymax=this.yboundary('max',ymax);
if(this.ymin==this.ymax){
如果(ymin){
这个.ymin-=1;
}
这是1.ymax+=1;
}
如果(((u ref=this.options.axes)==true | | | | | | u ref==='both'| | | | | | u ref==='y')| | this.options.grid==true){
如果(this.options.ymax===this.gridDefault