1
votes

I have a MSChart object which draws, among others, a line chart. The Y axis represents the value of the equity, and the X axis represents a DateTime. Using a combo box, the user is able to change the interval of the X axis. For instance, choosing a value of "One day" will force the X axis to show one bar every day:

http://i.imgur.com/pY1c2Mw.png

However, that is not sufficient. In addition to this, whenever the user changes the time scale of the X axis, I would like for the chart to zoom in from the first point contained in the chart to the first interval mark of the X axis it finds. In simpler terms, I would like to do this:

http://i.imgur.com/MwTZO9c.png

Automatically. However, I am stuck, because I do not know how to find the "position" of the first interval mark on the X axis. I know I want to zoom in from the first data point to the interval mark, but how can I do that when I do not know how big it can be? Please remember that the user can change the time scale himself, so I cannot use hard-coded values for this.

I would greatly appreciate any help you can give me, as I have been unable to find anything conclusive so far.

EDIT : Here's what I found so far. In more precise terms, the thing I'm looking for is the position of the FIRST grid line of the X axis' major grid. However, when the major grids for both axis are drawn, they are not given a real position, or at least that position is not contained within a propriety. Ergo, that position would have to be calculated - but how?

1

1 Answers

0
votes

Define an event trigger:

SelectionRangeChanged += new EventHandler<CursorEventArgs>(your_handler_function);

and inside the definition of your function:

public void your_handler_function(object sender, CursorEventArgs e)
{
    e.NewSelectionStart; // the beginning of the new range 
    e.NewSelectionEnd;   // the end of the new range
}