2011-05-10 72 views
0

請參考我的圖表鏈接。通過javascript處理選擇

http://www.humblesoftware.com/finance/index(定製此)

基本上要求是,只有一個月的選擇可在一個時間點來製備。(從子圖表)

如果選擇是從左側製成我只是簡單地加30到另一個值

xmin = Math.floor(area.x1); 
xmax = xmin+30; 

但是,如果選擇是從右側進行,那麼如何處理?

(意思是如果首先選擇xmax那麼我該如何處理xmin的值)?

+2

做相反的事情...設置'xmax'到選定的價值和'xmin'到價值減去30天 – Chad 2011-05-10 15:50:54

+0

謝謝你乍看,你的意思是xmax = Math.ceil(area.x2);和xmin = xmax-30但我如何處理這?任何示例代碼請 – Kiran 2011-05-10 16:08:07

+0

@Chad:那麼取決於'area.x1'被點擊的位置,這可能會返回或轉發?看起來像是最終用戶的混淆解決方案。 – 2011-05-10 17:01:02

回答

1

沒有太多瞭解的情況,這樣的事情應該做的:

// set the xmin to where they click 
xmin = Math.floor(area.x1); 

// make x-max the + 30 as you normally do 
xmax = xmin + 30; 

// now add a check to make sure we're not off the chart 
// if we are, make the chart's last possible X value the 
// x max, and subtract 30 from that to go backwards (and 
// it may be a good idea to check if xmin is under the 
// chart's min x value. 
if (xmax > chart.xmax){ 
    xmax = chart.xmax; 
    xmin = xmax - 30; 
    if (xmin < chart.xmin){ 
    xmin = chart.xmin; 
    } 
} 
+0

布拉德,這樣我獲得xmin和xmax值xmin = Math.floor(area.x1); xmax = Math.ceil(area.x2);你能告訴我們代碼的工作原理嗎? – Kiran 2011-05-10 16:50:09

+0

@Kiran:那麼檢查對方以找到更大的數字(對於頂部範圍)和更少的數字(對於底部範圍)? 'xmin = area.x1; xmax = area.x2;如果(xmin> xmax){xmin = xmin + xmax; xmax = xmin-xmax; xmin = xmin-xmax; } xmin = Math.floor(xmin); xmax = Math.ceil(xmax);'可能? – 2011-05-10 17:10:08