Zoom and Magnifier

When dealing with a huge number of data points, especially with Line series or HighLow series, a zoom functionality or a magnifier can be useful. With methods control.Zoom() or control.Magnifier() you can easily add these functionality to your charts.

Basically you can choose, when using the zoom mode, between an internal redraw of the zoomed area in the actual chart or an external redraw in a second chart control. When using the magnifier, the redraw of the magnified area must always happen in a second chart control. Zooming with an internal redraw is very simple: add a call to control.Zoom() (with the appropriate nMode parameter) to your source somewhere before control.Draw(). Click with the left mouse button onto your chart and draw a rectangle around the area, you want to be zoomed, release the mouse button - that's it. Of course you can zoom the zoomed area again and again, going deeper and deeper into the data jungle. With a right mouse button click (backwards) and a Shift+right mouse button click (forwards) you can browse between multiple zoom states. The middle mouse button redraws the original (unzoomed) chart.

When using the magnifier (or when you choose to do your on redrawing when zooming), things are slightly more difficult. First of all, you must - of course - add a second chart control to your window/form, which will show the zoomed or magnified area. Zooming itself works like abovementioned, for the magnifier call control.Magnifier() somewhere before control.Draw(), click with the left mouse button onto your chart and move the small magnifier rectangle over the data points, you want to get magnified. When certain mouse events happen, you must retrieve the information, which data points are included in the zoom area or get covered from the magnifier rectangle, than feed the scond chart with the appropriate data points and redraw it. Note: with Shift + Left mouse click onto the magnififer rectangle you can increase the initial size of the rectangle by 3 pixels, with Shift + Right mouse click you can decrease it by 3 pixels.

How do you get these informations? The structure tRMC_INFO holds all necessary data for you after each relevant mouse click. Member nChartType will hold either the constant RMC_ZOOM_MODE (-99) or RMC_MAGNIFIER_MODE (-98) to indicate, that the chart is in a zoom or magnifier mode. The members nData1 to nData4 (for series 1 to 4) and nVirtData1 to nVirtData4 (for series 5 to 8) will hold (if the appropriate series exist and is covered by the zoom or magnifier rectangle) an 8-byte value. The lower 4 byte of this value hold the index of the first data element, the higher 4 byte hold the index of the last data element, which is covered by the zoom/magnifier rectangle. (If you don't know how to split the 8-byte value into the lower and higher part, you can use functions control.GetLowPart() and control.GetHighPart().)

Restrictions, you should note: The chart area, which shall be zoomed or magnified, must always be in the first region, the maximum number of series, this region may have, is 8. Use this functionality only with gridbased series, and don't use it with complex figures such as stacked or grouped bars/lines.


To understand, how the decision is made, which data points get included when covered by the zoom or the magnifier rectangle, look at this chart: the index of the first data element will be 8, the index of the last data element will be 16. So also data points 11, 13 and 14 are included, although they are not covered by the rectangle.



With HighLow series, the zoom or magnifier rectangle must cover the whole width and either the top or the bottom of the first and last HighLow object, to identify the data row, which shall be zoomed. In this example, bars 6,7,8,9 and 10 will be included. Object #5 is not included, because it's width is not totally coverd by the rectangle, objects 11 and 12 are not included, because the rectangle does not cover either their top or bottom.

The following mouse events in the chart are important and should be monitored:
Mouse event Necessary action.
Left mouse button down Only important for magnifier: rectangle draws initially. If this initial drawing covers data points, a first redrawing of the magnified chart should happen.
Shift + Left mouse button down Only important for magnifier: the magnifier rectangle shrinks by 3 pixel. If this shrinking happens on data points, a redrawing of the magnified chart should happen.
Shift + Right mouse button down Only important for magnifier: the magnifier rectangle increases by 3 pixel. If this enlargement happens on data points, a redrawing of the magnified chart should happen.
Mouse move Only important for magnifier: the rectangle gets moved over the chart. Check, if data is covered by the rectangle and redraw the magnified chart.
Left mouse button up: Only important for zooming: the zoom rectangle is finished (=painted), check, if data points are covered and redraw the zoomed chart.