2014-09-03 87 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 
}