2014-09-03 75 views
0

当我创建具有以下选项海军报的图形绘制图形正确:flot打标功能,轴没有定义?

var options = { 
      colors: trendcolors, 
      series: { 
       points: { 
        show: true 
       }, 
       lines: { 
        show: true 
       } 
      }, 
      xaxis: { 
       mode: "time", 
       axisLabel: "Date/Time", 
       tickLength: 0 
      }, 
      yaxis: { 
       axisLabel: "Duration (Sec)" 
      }, 
      selection: { 
       mode: "x" 
      }, 
      grid: { 
       hoverable: true, 
       clickable: true, 
       markings: function (axes) { 
        var markings = []; 
        var date = new Date(axes.xaxis.min); 
        date.setUTCSeconds(0); 
        date.setUTCMinutes(0); 
        date.setUTCHours(0); 
        var i = date.getTime(); 
        do { 
         markings.push({xaxis:{from: i, to: i + (24 * 60 * 60 * 1000) }, color: colormarking }); 
         i += ((24 * 60 * 60 * 1000) * 2); 
        } while (i < axes.xaxis.max); 
        return markings; 
       } 
      }, 
      legend: { 
       labelFormatter: function(label, series) { 
          return label + " (" + series.data.length + ")"; 
         } 
      } 
     }; 

但是,当我改变标记匿名函数的标准功能出现错误和海军报未能绘制图形,因为“轴'未在fMarkings行中定义。为什么是这样?有什么不同?

var options = { 
     colors: trendcolors, 
     series: { 
      points: { 
       show: true 
      }, 
      lines: { 
       show: true 
      } 
     }, 
     xaxis: { 
      mode: "time", 
      axisLabel: "Date/Time", 
      tickLength: 0 
     }, 
     yaxis: { 
      axisLabel: "Duration (Sec)" 
     }, 
     selection: { 
      mode: "x" 
     }, 
     grid: { 
      hoverable: true, 
      clickable: true, 
      markings: fMarkings(axes) 
     }, 
     legend: { 
      labelFormatter: function(label, series) { 
         return label + " (" + series.data.length + ")"; 
        } 
     } 
    }; 

顺便说一下,fMarkings是在另一个js块中全局定义的。

回答

1

markings参数需要一个函数或数组。你正在做的是在你定义选项对象时调用函数。当你在那里调用它时,axis变量不存在。你所需要的仅仅是:

grid: { 
     hoverable: true, 
     clickable: true, 
     markings: fMarkings 
    }, 

哪里fMarkings是一个函数,如:

fMarkings = function(axes){ 
    return arrayOfMarkings 
}