2013-04-03 104 views

回答

6

作爲danvk mentioned before,請嘗試在"new Dygraph()"調用中指定"underlayCallback"選項。使用HTML Canvas上下文繪製線條。

實施例下面: (XMIN和XMAX以毫秒爲單位的Unix紀元時間)

var yavg= 50, xmin=1357016400000, xmax=1359694800000; 
new Dygraph(document.getElementById('graph1'), data,{ 
    (....other options....), 
    underlayCallback:function(ctx,area,dygraph){  
    var xl = dygraph.toDomCoords(xmin,yavg); 
    var xr = dygraph.toDomCoords(xmax,yavg); 
    ctx.strokeStyle= 'green'; 
    ctx.beginPath(); 
    ctx.moveTo(xl[0],xl[1]); 
    ctx.lineTo(xr[0],xr[1]); 
    ctx.closePath(); 
    ctx.stroke();  
}});