0

Please refer to the link of my chart .

http://www.humblesoftware.com/finance/index (Customized this )

Basically the requirement is that , only one month of selection can be made at a point of time .(From the child chart)

If the selection is made from left side , i am simply adding 30 to the other value

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

But if the selection is made from the right side then how to handle this ??

(Means if the xmax is selected first then how can i handle the xmin value )??

Brad Christie
102k16 gold badges160 silver badges200 bronze badges
asked May 10, 2011 at 15:45
3
  • 2
    do the opposite...set xmax to the selected value and xmin to that value minus 30 days Commented May 10, 2011 at 15:50
  • Thank you chad , you mean xmax = Math.ceil(area.x2); and xmin = xmax-30 ?? But how can i handle this ?? any sample code please Commented May 10, 2011 at 16:08
  • @Chad: So depending where area.x1 is clicked, this could potentially back or forward-date? Seems like a confusion solution to the end-user. Commented May 10, 2011 at 17:01

1 Answer 1

1

Without knowing too much about the situation, something like this should do:

// 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;
 }
}
answered May 10, 2011 at 15:52
Sign up to request clarification or add additional context in comments.

2 Comments

Brad , this way i obtain the xmin and the xmax values xmin=Math.floor(area.x1); xmax = Math.ceil(area.x2); could you please tell how ur code works ??
@Kiran: So check against each other to find the greater number (for the top range) and lesser number (for the bottom range)? xmin = area.x1; xmax = area.x2; if (xmin > xmax){ xmin = xmin + xmax; xmax = xmin - xmax; xmin = xmin - xmax; } xmin = Math.floor(xmin); xmax = Math.ceil(xmax); possibly?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.