C++ Charting Library Walk-through: source code adding cpp charts to Win32 EXE.

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

  • See the new v8 demo (only 15 meg and uninstalls no problem.)
  • Includes 100% Native Charting Library Demo as well as WPF and Winform EXEs for comparison.
  • 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...
c++ charting library for finance and business c++ charting library 3d surface scatter wireframe terrain

The following demonstrates your first Visual Studio Visual C++ Win32 Charting implementation. This example is an absolute minimal Visual Studio Win32 project. For a VS2013 MFC project, see the MFC Charting Library VS2013 walk-through. The product eval comes with a large MFC example project.

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

The ProEssentials setup 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++ - -Win32 ], select project template [Win32 Project], and supply a project name [MyFirst] and project location.

C++, CPP, Win32 Starting Visual Studio Project.
Project / Add Existing Item... menu
1) Copy "PEGRPAPI.H" and "PEGRP32F.LIB" from the C:\ProEssentials8\VC demo directory to where the [MyFirst] 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.

c++. cpp. adding header file and import library.
myfirst.cpp... Adding ProEssentials Charting header file ...
c++ / cpp code declaring include file.

 

3) Open the file "myfirst.cpp" and near the top add the lines:

#include "Pegrpapi.h"
HWND hPE;



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

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

myfirst.cpp... Init Window handle...
C++ / CPP code to initialize hWND 4) Then within file "myfirst"s InitInstance, initialize hPE to NULL.

hPE = NULL;






myfirst.cpp... near top of WndProc

5) Near the top of WndProc, add variables used later to initialize the chart.

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


c++ / cpp variables inside WndProc.

myfirst.cpp message switch statement...

6) Add the below message switch statements. See images below for clarity.

case WM_CREATE: initialzes a chart after parent creates it's window

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);
case WM_DESTROY: cleans up the chart resource at same time parent is cleaned up

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

case WM_SIZE fills client rect of parent with chart, ERASEBKGND prevents flicker

case WM_SIZE:
if (hPE)
{
GetClientRect(hWnd, &r);
MoveWindow(hPE, 0, 0, r.right, r.bottom, FALSE);
}
break;

case WM_ERASEBKGND: // Adding this prevents flashing on resize
break;

case WM_COMMAND: 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);
_stprintf(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...
c++ / cpp code window 1.

c++ / cpp code window 2


myfirst.cpp Charting Results... Congratulations...
C++  MyFirst.cpp Charting Library
Run your project and you'll see a similar form. Add tabs, right click the chart to make changes, etc.

Congratulations, you've just completed your first C++ 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