2011-05-10 127 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