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
1 Answer 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
Brad Christie
102k16 gold badges160 silver badges200 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Kiran
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 ??
Brad Christie
@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?lang-js
xmaxto the selected value andxminto that value minus 30 daysarea.x1is clicked, this could potentially back or forward-date? Seems like a confusion solution to the end-user.