In-depth introduction to CChart daily course-Happy high 4 Lesson 15th Rome tongtu, using the ChartCtrl control to achieve multi-area plotting, cchartchartctrl

Source: Internet
Author: User

In-depth introduction to CChart daily course-Happy high 4 Lesson 15th Rome tongtu, using the ChartCtrl control to achieve multi-area plotting, cchartchartctrl

It is common to draw multiple images in one window. In the previous course, I have introduced three multi-area plotting methods. Multi-area plotting using split view, multi-area plotting using CChart class, and multi-area plotting using CChartWnd class. Among them, the third method is implemented by the dummies recently. In earlier versions, CChartWnd can only draw one graph.

Because the ChartCtrl control is provided in the new version, it is stupid to find that using this control to achieve multi-region plotting is the most perfect.

In fact, from the content of the previous three lessons, the friends must have known how to use ChartCtrl to draw multiple diagrams. Although there is only one graph at a time, however, you can draw Multiple Graphs in the same way.

It's so stupid to give a complete demonstration.

Step 1: Create a dialog box-based MFC program LessonA15.

Step 2: copy the CChart library file to the LessonA15 directory.

Step 3: Use the resource editor to open the Main Dialog Box, delete the "TODO: Set dialog Control here" label, and add two Custom controls with the IDS IDC_CHART1 and IDC_CHART2 respectively, its class is set to ChartCtrl.

The dialog box layout is roughly as follows.


Step 4: Open the LessonA15Dlg. cpp file, add the CChart header file and reference the imported/imported file to the header, and add the math header file.

#include <math.h>#include "Chart.h"#ifdef _DEBUG#if defined(_UNICODE) || defined(UNICODE)#pragma comment(lib, "PlotDll_ud.lib")#else#pragma comment(lib, "PlotDll_d.lib")#endif#else#if defined(_UNICODE) || defined(UNICODE)#pragma comment(lib, "PlotDll_u.lib")#else#pragma comment(lib, "PlotDll.lib")#endif#endif

 

Step 5: Add a function before the OnInitDialog function to draw a contour line.

double func(double x, double y){return 1.0/((x-1.5)*(x-1.5)+(y-0.8)*(y-0.8)+1.0)+1.0/((x+1.5)*(x+1.5)+(y-0.8)*(y-0.8)+1.0)+1.0/(x*x+(y+0.8)*(y+0.8)+1.0);}

Step 6: add the drawing code in the OnInitDialog function as follows.

// TODO: Add extra initialization hereCWnd * pWnd; CChart * chart; pWnd = GetDlgItem (IDC_CHART1); chart = GetChart (pWnd-> m_hWnd); chart-> SetType (kTypeContour ); chart-> SetFieldFcn (func); chart-> SetPlotRange (-2, 2,-2, 2); chart-> SetContourLineNum (80 ); chart-> SetTitle (_ T ("Abe"); chart-> SetBkgndColor (GetSysColor (COLOR_3DFACE); chart-> SetEdgeShow (true); pWnd = GetDlgItem (IDC_CHART2 ); chart = GetChart (pWnd-> m_hWnd); chart-> AddPoint2D (10.0, 0.0); chart-> AddPoint2D (9.7, 6.0); chart-> AddPoint2D (0.0, 6.0 ); chart-> AddPoint2D (0.025, 5.5); chart-> AddPoint2D (9.225, 5.5); chart-> AddPoint2D (9.5, 0.0); chart-> AddPoint2D (10.0, 0.0 ); chart-> AddPoint2D (6.0, 5.5, 1); chart-> AddPoint2D (6.15, 2.5, 1); chart-> AddPoint2D (9.375, 2.5, 1 ); double pX [100], pY [100]; int I; for (I = 0; I <100; I ++) {pX [I] = 7.7 + 0.5 * cos (I * 2.0*3.1415926536/100.0 ); pY [I] = 4.0 + 0.5 * sin (I * 2.0*3.1415926536/100.0);} chart-> AddCurve (pX, pY, 100 ); chart-> SetDataColor (RGB (20, 20, 20), 0); chart-> SetDataColor (RGB (20, 20, 20), 1 ); chart-> SetDataColor (RGB (20, 20, 20), 2); chart-> SetDataLineSize (3, 0); chart-> SetDataLineSize (3, 1 ); chart-> SetDataLineSize (3, 2); chart-> SetXRange (-2, 12); chart-> SetYRange (-5, 10 ); chart-> SetTitle (_ T ("dog slab"); chart-> SetBkgndColor (GetSysColor (COLOR_3DFACE); chart-> SetEdgeShow (true );

Now you can run the program and result.


The parade is about to take place tomorrow.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.