MFC 2D Dynamic Chart [GDI]

Source: Internet
Author: User

 

Source blog: http://www.codeproject.com/Articles/9350/2D-Animated-Charts

Source code: http://download.csdn.net/detail/nuptboyzhb/4202051

Introduction: cgraphobject is derived from the cwnd class. Therefore, the cgraphobject class isWindow Type; That is, each chart is a window; therefore, the creation of each chart should be placed in the oncreate function or oninitialupdate function; its application process, and window-type controls (such as cbutton) very similar;

Application:

1.
Copy the related. h and. cpp files to the project directory and load them to the project;

[Graphobject. h graphobject. cpp]

[Mathparams. H]

[2dlinegraph. h 2dlinegraph. cpp]

[2dbargraph. h 2dbargraph. cpp]

[2dpiegraph. h 2dpiegraph. cpp]

2.
Include the corresponding header file in the header file where the class is located; # include "graphobject. H" and define the corresponding resource ID window;

3.
Add a pointer of the chart type to the class as its member variable;

Cgraphobject * m_pgraphobject1;

//...... For details, see the code.

4.
In the oninitialupdate () function of the View class, initialize these chart windows, or the oninitdialog () function of the dialog box; or the oncreate function. (Note: the first function called by the framework after the View window is fully created. The framework will call oninitialupdate before ondraw is called for the first time)

 

// Create cgraphobject1 (2 dpie graph)

M_pgraphobject1 = new cgraphobject ();

// Create a chart window, size, pointer to the parent window, and resource ID (custom)

M_pgraphobject1->Create(Null, crect (240,220,), this,
Id_object_graph_1, Null );

// Note that the resource ID should be defined in the header file, for example: # define id_object_graph_1 12345

// Create graph and set graph Parameters

M_pgraphobject1-> creategraph (gt_2dpie); // create a two-dimensional pie chart

M_pgraphobject1-> setgraphbackgroundcolor (RGB (255,255,255); // you can specify the background color.

M_pgraphobject1-> setgraphtitle ("2 dpie No. 1"); // set the title

M_pgraphobject1-> setgraphsubtitle ("animation-none"); // you can specify a subtitle.

M_pgraphobject1-> setgraphtitleshadow (false); // The title has no shadow.

M_pgraphobject1-> setgraphsubtitleshadow (false); // The subtitle has no shadow.

M_pgraphobject1-> setgraphtitlecolor (RGB (128,128,128); // you can specify the title Color.

M_pgraphobject1-> setgraphsubtitlecolor (RGB (, 96); // you can specify the subtitle color.

// Set the background color of the comment

M_pgraphobject1-> setgraphlegendbackgroundcolor (RGB (208,208,208 ));

// Add graph segments

// Add data segments (percentages, colors, and names) for the pie chart)

M_pgraphobject1-> add2dpiegraphsegment (40, RGB (255, 0), "seg_1 ");

M_pgraphobject1-> add2dpiegraphsegment (25, RGB (0,255, 0), "seg_2 ");

M_pgraphobject1-> add2dpiegraphsegment (15, RGB (255,), "seg_3 ");

M_pgraphobject1-> add2dpiegraphsegment (5, RGB (255, 0, 255), "seg_4 ");

M_pgraphobject1-> add2dpiegraphsegment (8, RGB (0,255,255), "seg_5 ");

M_pgraphobject1-> add2dpiegraphsegment (7, RGB (255,255, 0), "seg_6 ");

// Set image Animation

M_pgraphobject1-> setgraphanimation (false, at_pie_draw );

5.
Delete the pointer of the member variable in the View class destructor;

M_pgraphobject1-> destroywindow (); // close the window

Delete m_pgraphobject1; // Delete the pointer

Note: I have modified mathparams. h and added

# Pragma comment (Lib, "gdi32.lib ")

# Pragma comment (Lib, "msimg32.lib ")

And include mathparams. h In the. cpp file of the three images.

Package it into the DLL Dynamic Link Library

Source code: http://download.csdn.net/detail/nuptboyzhb/4205148

After encapsulation, you only need to [2dgraph. lib] [2dgraph. DLL] [graphobject. h] copy the three files to the project directory. You only need to include the header file where necessary;

# Include "graphobject. H"

# Pragma comment (Lib, "2dgraph. lib ")

Then, the following programming is the same as the above 3-5 steps;

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.