MFC Charting VS2013 Walk-through adding charts to your MFC EXE in C++.

See the quick big picture and your native charting library potential in C++, MFC ...

  • See the new v8 demo (only 15 meg and uninstalls no problem.)
  • Includes 100% Native Charting Library Demo plus WPF and Winform EXEs.
  • Size, Shape, Right Click, Export, Zoom (especially date and log scales), Pan, and Rotate.
  • Study the code to discover the ease of use.
  • Your company, team, vendors, and end-users deserve the best.
See the demo...
mfc charting library for finance engineering and more mfc charting library 3d surface scatter wireframe terrain

The following information demonstrates how to create your first minimal Visual Studio Visual C++ MFC Charting implementation. If you prefer an absolutely minimal Win32 Hello World type project without use of MFC, see Win32 C++ Charting Library. The product eval installs a large MFC example project.

IMPORTANT: For help finding DLL specific features in our help system, click the Contents Tab at the top-left location, then near the bottom click ProEssentials Reference, and then see the Alphabetic Listing. The .Net Reference section is the best source for researching properties.

When installing ProEssentials, the setup program installs the ProEssentials DLL into the System32 directory, SysWow64 on 64 bit systems. It also installs a header file and import library into the C:\ProEssentials8\VC directory. The relevant files are:

PEGRP32F.DLL ProEssentials Pro DLL
PEGRP32F.LIB ProEssentials Pro LIB File
PEGRPAPI.H ProEssentials Header File
PEGRPSF.DLL ProEssentials Standard DLL
PEGRPSF.LIB ProEssentials Standard   LIB File

File / New... menu

Creating the Project...

Launch Visual Studio and use the File / New... menu to launch the [New] project dialog. Within Tree select [Visual C++ - - MFC ], select project template [MFC Application], and supply a project name [MyFirstMfc] and project location.

Mfc Dll charting library starting visual studio project.
Select a standard MFC style project and some favorite MFC options...

Mfc visual studio project settings.

Mfc library with Ribbon menu.

Project / Add Existing Item... menu
1) Copy "PEGRPAPI.H" and "PEGRP32F.LIB" from the C:\ProEssentials8\VC demo directory to where the [MyFirstMfc] project is located.

Note, if usingStandard version, use "PEGRPSF.LIB".

2) Use the [Project / Add Exiting Item...] menu to add "PEGRPAPI.H" and "PEGRP32F.LIB" to the [MyFirstMfc"] project.

The image shows the existing files being added to your project.

Adding header file and import library to MFC project.
myfirstmfcview.cpp... Adding ProEssentials Charting header file ...
Declaring the charting header file.

 

3) Open the file "myfirstmfcview.cpp" and near the top add the line:

#include "Pegrpapi.h"



The include statement adds the ProEssentials header file which contains constants and function declarations.

myfirstmfcview.h... Adding Window handle variable...
Declare the charting Windows handle. 4) Open the file "myfirstmfcview.h" and add the line:

HWND hPE;



The variable hPE is used to store the Window's handle for the ProEssentials chart control.

Each instance of MyFirstMfcView will have its own copy of this handle.

Then within file "myfirstmfcview.cpp"s constructor, initialize hPE to NULL.

hPE = NULL;



Initialize the charting handle.


Open Class Wizard for CMyFirstMfcView...

MFC Classwizard Right Click Menu.Visual Studio MFC Classwzard select Class Wizard... menu

5) Left click Class View within the solution explorer. Right click CMyFirstMfcView and select Class Wizard...

Select the Messages Tab and double click the messages...

    WM_CREATE

    WM_DESTROY

    WM_ERASEBKGND

    WM_SIZE

MFC ClassWizard, add Messages by double clicking WM_CREATE etc.

Select the Virtual Functions Tab and double click the OnCommand function...

MFC ClassWizard double click OnCommand to add virtual function.

myfirstmfcview.cpp...

6) Within the recently added OnCreate, OnDestroy, OnSize, and OnCommand sections of MyFirstMfcView.cpp, add the following code that initializes an example chart. See images below for further reference.

OnCreate: initialze a chart after parent creates it's window

RECT r;
int s, p;
int dwColor;
float f[] = {10, 30, 20, 40, 30, 50, 15, 63, 74, 54, 25, 34};

GetClientRect(&r);
hPE = PEcreate(PECONTROL_GRAPH, 0, &r, this->m_hWnd, 1000);
PEszset(hPE, PEP_szMAINTITLE, TEXT("Hello World"));
PEszset(hPE, PEP_szSUBTITLE, TEXT(""));
PEnset(hPE, PEP_nSUBSETS, 2);
PEnset(hPE, PEP_nPOINTS, 6);
for (s=0; s<2; s++)
{
for (p=0; p<6; p++)
{ // (s*6)+p or (SubsetIndex * NumberPoints) + PointIndex
PEvsetcellEx(hPE, PEP_faYDATA, s, p, &f[(s*6)+p]);
}
}
// or Pass data in one call is much faster -> PEvset(hPE, PEP_faYDATA, f, 12);
PEvsetcell(hPE, PEP_szaPOINTLABELS, 0, TEXT("Jan"));
PEvsetcell(hPE, PEP_szaPOINTLABELS, 1, TEXT("Feb"));
PEvsetcell(hPE, PEP_szaPOINTLABELS, 2, TEXT("Mar"));
PEvsetcell(hPE, PEP_szaPOINTLABELS, 3, TEXT("Apr"));
PEvsetcell(hPE, PEP_szaPOINTLABELS, 4, TEXT("May"));
PEvsetcell(hPE, PEP_szaPOINTLABELS, 5, TEXT("June"));
PEvsetcell(hPE, PEP_szaSUBSETLABELS, 0, TEXT("For .Net Framework"));
PEvsetcell(hPE, PEP_szaSUBSETLABELS, 1, TEXT("or MFC, ActiveX, VCL"));
PEszset(hPE, PEP_szYAXISLABEL, TEXT("Simple Quality Rendering"));
PEszset(hPE, PEP_szXAXISLABEL, TEXT(""));
dwColor = PERGB(60, 0, 180, 0); PEvsetcell(hPE, PEP_dwaSUBSETCOLORS, 0, &dwColor);
dwColor = PERGB(180, 0, 0, 130); PEvsetcell(hPE, PEP_dwaSUBSETCOLORS, 1, &dwColor);
PEnset(hPE, PEP_nGRAPHPLUSTABLE, PEGPT_BOTH);
PEnset(hPE, PEP_nDATAPRECISION, 0);
PEnset(hPE, PEP_bLABELBOLD, TRUE);
PEnset(hPE, PEP_nPLOTTINGMETHOD, PEGPM_BAR);
PEnset(hPE, PEP_nGRADIENTBARS, 8);
PEnset(hPE, PEP_bBARGLASSEFFECT, TRUE);
PEnset(hPE, PEP_nLEGENDLOCATION, PELL_LEFT);
PEnset(hPE, PEP_nDATASHADOWS, PEDS_3D);
PEnset(hPE, PEP_nFONTSIZE, PEFS_LARGE);
PEnset(hPE, PEP_bPREPAREIMAGES, TRUE);
PEnset(hPE, PEP_bCACHEBMP, TRUE);
PEnset(hPE, PEP_nRENDERENGINE, PERE_DIRECT2D);
PEnset(hPE, PEP_bANTIALIASGRAPHICS, TRUE);
PEnset(hPE, PEP_bANTIALIASTEXT, TRUE);
PEnset(hPE, PEP_bALLOWDATAHOTSPOTS, TRUE);
PEnset(hPE, PEP_bBITMAPGRADIENTMODE, FALSE);
PEnset(hPE, PEP_nQUICKSTYLE, PEQS_LIGHT_SHADOW);
PEnset(hPE, PEP_bFIXEDFONTS, TRUE);
PEreinitialize(hPE);
PEresetimage(hPE, 0, 0);

OnDestroy: cleans up the chart resource at same time parent is cleaned up

if (hPE) { PEdestroy(hPE); hPE = 0; }

OnSize: this causes chart to always fill client rect of parent

if (hPE)
{
RECT r; GetClientRect(&r);
::MoveWindow(hPE, 0, 0, r.right, r.bottom, FALSE);
}

OnCommand: this handles the hot spot event, showing a message box.

int wmId = LOWORD(wParam);
int wmEvent = HIWORD(wParam);
switch (wmEvent)
{
case PEWN_CLICKED:
HOTSPOTDATA hsd; TCHAR buffer[128]; float yvalue;
PEvget(hPE, PEP_structHOTSPOTDATA, &hsd);
if (hsd.nHotSpotType == PEHS_DATAPOINT)
{
PEvgetcellEx(hPE, PEP_faYDATA, hsd.w1, hsd.w2, &yvalue);
swprintf_s(buffer, TEXT("DataPoint %d value %.2f"), hsd.w2, yvalue);
::MessageBox(this->m_hWnd, buffer, TEXT("Hello World"), 0);
}
break;
}

MainTitle and SubTitle are set first. Note that setting SubTitle to an empty string hides the subtitle.

Subsets and Points define the amount of data you'll be passing.

Next, we pass some random data into the Y Data two dimensional property array.

PointLabels sets the data point labels located below axis.

SubsetLabels sets the subset legend text.

Next, we set various other properties controlling visual aspects, and enable flicker free updates with PrepareImages.

Finally PEreinitialize and PEresetimage tells ProEssentials to initialize and resetimage the image, in other words, you're done setting properties.

Your code window will look similar to below...
MFC source code window 1.

MFC source code window 2.


MFC Charting Results... Congratulations...

MFC Charting Library

Mfc Chart

 


Run your project and you'll see a similar form. Add tabs, right click the chart to make changes: change colors, hide legend, change plotting method, etc.

Congratulations, you've just completed your first MFC Charting ProEssentials implementation.
Online developer reference

Complete online technical reference to the ProEssentials product. The .NET Reference is the best mechanism to navigate the large quantity of properties and features.  Walk-Throughs of charting in VB.NET, C#.NET, ASP, VC, VB6, and Delphi get you started quickly.

learn more about our charting library in Chapter 5

Online interactive demo

Financial, Engineering, Scientific, and Business examples give you an instant taste of ProEssentials' power.

mfc c++ chart demo

Letter from the President

Thank you for researching. Call, email and let's talk charting.

Thank you.