Graphing Library example of C++ Graphs for Win32 and Win64. Other examples available on this site.

[ Graphing Library via Dynamically Linkable Library ]

The following demonstrates how to create your first Visual Studio VS2005 C++ Charting Library implementation. Click here for a more uptodate VS2013 walkthrough MFC Charting in VS2013

The ProEssentials DLL has a standard C interface like all Windows system DLLs.

This example is a non-MFC example for reasons of simplicity. This article teaches the fundamentals that ProEssentials creates an HWND much like the CreateWindow API call. Then the control is utilized similar to any child window within the Windows operating system.

Also see the included ProEssentials/VC complete MFC example project which replicates our main demo. File PeView.CPP contains all chart related code.

There are notes for MFC throughout this article.

For help finding DLL features within our help system, use the Contents Tab at the top-left location, then near the bottom click "ProEssentials Reference", and then "Alphabetic Listing".

File / New... menu Installation...

Library for Win32 Application

When installing ProEssentials, the setup program installs the ProEssentials DLL (our Dynamically Linkable Charting Library) into the system directory. 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
 
PEGRPLF.DLL ProEssentials Lite DLL
PEGRPLF.LIB ProEssentials Lite LIB File

Note this Walk-Through uses the Pro version. Substitute the above Standard or Lite Charting Library file as needed.

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 appropriate project location.


Project / Add Existing Item... menu Adding ProEssentials to a VC project...
Using our Charting Library in a Hello World App.

1) Copy "PEGRPAPI.H" and "PEGRP32F.LIB" from the C:\ProEssentials8\VC directory to where the [MyFirst] project is located.

Note, if using Standard or Lite versions, use "PEGRPSF.LIB" or "PEGRPLF.LIB".

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

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

 

 


myfirst.cpp... Adding declarations and Window handle variable...
Adding Graphing Library header files and import lib.

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 control.

Note: Within an MFC application, you'll generally add the include statement to the view class's ".cpp" file and add the variable m_hPE to the view class's ".h" file as a member variable of the view's class.


myfirst.cpp...
Declaring a handle to store charting control handle.

4) Within the InitInstance function, add one line of code to initialize hPE to NULL. This is needed because we'll be adding code into the WM_SIZE and WM_DESTROY switches which assume a non-NULL hPE represents a ProEssentials control has been constructed.

hPE = NULL;


Add a few variables... WndProc
Other graphing variables.

5) Next, within the WndProc function, add the lines:

RECT r;
int s, p;
float f;

These will be needed within the WM_CREATE and WM_SIZE switches.


myfirst.cpp... WM_CREATE, WM_SIZE
Source code creating a graph via library.

case WM_CREATE:
     GetClientRect(hWnd, &r);
     hPE = PEcreate(PECONTROL_GRAPH, 0, &r, hWnd, 1000);
     PEnset(hPE, PEP_bPREPAREIMAGES, TRUE);
     PEnset(hPE, PEP_nSUBSETS, 2);
     PEnset(hPE, PEP_nPOINTS, 10);
     for (s=0; s<2; s++)
     {
         for (p=0; p<10; p++)
         { 
            f = (rand() % 10) + (rand() % 100) / 100.0F;
            PEvsetcellEx(hPE, PEP_faYDATA, s, p, &f);
         }
     }
     PEszset(hPE, PEP_szMAINTITLE, TEXT("My Title"));
     PEszset(hPE, PEP_szSUBTITLE, TEXT(""));
     PEszset(hPE, PEP_szYAXISLABEL, TEXT("My Data"));
     PEszset(hPE, PEP_szXAXISLABEL, TEXT(""));
     PEvsetcell(hPE, PEP_szaSUBSETLABELS, 0, TEXT("Hello"));
     PEvsetcell(hPE, PEP_szaSUBSETLABELS, 1, TEXT("World"));
     PEnset(hPE, PEP_bBITMAPGRADIENTMODE, TRUE);
     PEnset(hPE, PEP_nQUICKSTYLE, PEQS_MEDIUM_NO_BORDER);
     PEnset(hPE, PEP_bFIXEDFONTS, TRUE);
     PEnset(hPE, PEP_nLEGENDSTYLE, PELS_1_LINE_INSIDE_AXIS);
     PEreinitialize(hPE);
     PEresetimage(hPE, 0, 0);
     break;

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

6) Next, we add handlers for the WM_CREATE, WM_SIZE, and WM_ERASEBKGNDmessage handlers.

WM_CREATE contains the ProEssentials creation code. The ProEssentials function PEcreate is similar to the Windows CreateWindow function, and if successful, returns a Windows handle which is stored in hPE.

PEnset is a ProEssentials function that sets 32 bit type properties such as INTEGER, BOOL and HANDLE.

Next a nested for loop passes data via PEvsetcellEx and the property YData. Note variable f is type float and this is important because PEvsetcellEx works by reading data at a void pointer's location and memory at this location must be of the type expected.

Next, PEszset is the ProEssentials function used to set textual type properties.

PEvsetcell is then used to set the Subset Legend text for both subsets.

PEnset is then used to set various properties controlling visual aspects.

PEreinitialize and PEresetimage tell ProEssentials you're done setting properties.

The code in the WM_SIZE message handler causes the ProEssentials control to always consume the entire Windows client area.

Consuming the WM_ERASEBKGND message prevents the control from flashing as the parent repaints itself.


myfirst.cpp... WM_DESTROY...

Calling PEdestroy to clean up resources of charting library.

7) The code in the WM_DESTROY message handler destroys the ProEssentials control and frees resources via PEdestroy.

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


Results... Congratulations...
Graphing ProEssentials charting library within your software!

Use Visual C++'s Build / Build myfirst.exe menu (short cut F7) and then Build / Execute myfirst.exe (short cut Ctrl+F5) and you'll see the resulting Window to the left.

Congratulations, you've just completed your first Visual C++ / ProEssentials implementation.

 


This example is very simple and you'll likely set other properties such as:

PointLabels which will replace the "1,2,3..." along x axis.

SubsetLineTypes which controls line styles.

SubsetColors which controls line colors.

PlottingMethod which controls the type of chart created, Line, Bar, Area, Point, etc.

MFC User's Note: ProEssentials installs an MFC example [VC6 Example Project] located via the Start Menu / All Programs / ProEssentials. This project will load into any version of Visual Studio. Allow the project to automatically convert as needed.Within an MFC implementation, you'll generally add a HWND m_hPE member variable inside the View Class's declaration and then ProEssentials creation code within the View Class's  OnCreate handler after the base class call. You'll use the OnDestroy message handler to call PEdestroy. Within our included ProEssentials8/VC example project, look for "PeView.h" for the m_hPE declaration and "PeView.cpp" for the 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 graphing in VB.NET, C#.NET, ASP, VC, VB6, and Delphi get you started quickly.

learn more about our Graphing Library, see Chapter 5

Online interactive demo

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

view our Graphing Library online

Letter from the President

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

Thank you.