In mature commercial software such as Origin, the layering function is essential for Drawing Images with multiple scales.
CChart currently contains two types of views with hierarchical functions. A hierarchical view is called. All layers in this view share the drawing area, and each layer draws its own axis. The other is shared X-axis view. All layers of this view share the X-axis except the drawing area. Each layer draws its own Y-axis separately.
This section describes the hierarchical view.
Create a VC6 project named Lesson11 in the way of the first lesson. For the WM_CREATE response routine, enter the following.
Case WM_CREATE: chartWnd. attach (hWnd, kTypeLayered); chartWnd. getChart ()-> ResizePlots (2); double pX [200], pY [200]; int I; for (I = 0; I <200; I ++) {pX [I] = I + 1; pY [I] = (I + 1) * (I + 1);} chartWnd. getChart ()-> AddCurve (pX, pY, 200, 0); for (I = 0; I <200; I ++) {pX [I] = (I + 1) * 10; pY [I] = sin (I * 2.0*3.1415926536/200.0);} chartWnd. getChart ()-> AddCurve (pX, pY, 200, 1); chartWnd. getChart ()-> SetTitle (_ T ("layer 1"), 0); chartWnd. getChart ()-> SetTitle (_ T ("Layer 2"), 1); break;
The hierarchical view code is kTypeLayered.
The ResizePlots function also appears in the previous lesson. In this lesson, the ResizePlots function is defined:
voidResizePlots(int nLayers);
This function is very easy to understand. Its Parameter nLayers indicates the number of layers.
The above code sets two layers.
Because the sine function of the math library is used earlier, add a reference to the header file of Lesson11.cpp.
#include <math.h>
Run the program.
650) this. width = 650; "src =" http://img.blog.csdn.net/20130918225713968? Watermark/2/text/plain =/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA =/dissolve/70/gravity/SouthEast "alt =" SouthEast "/>
We can see that the two curves with very different scales are drawn to the same graph.
Note that the current clumsy way to differentiate different layers is color. All elements of the same layer, including titles, curves, and axes, are in the same color.
You can use the mouse to test the interaction function of the hierarchical view.