Click here to Skip to main content
15,923,015 members
Articles / Desktop Programming / MFC

GDI+ Plot ActiveX Control

Rate me:
Please Sign up or sign in to vote.
4.89/5 (10 votes)
5 Sep 2013LGPL32 min read 92.3K   12.1K   65   13
GDI+ 2D plot ActiveX control
Image 1


The latest source code can be checked out from GitHub (


This is a simple OCX control, which allows you to plot two-dimensional data. Despite ProEssentials developed by Gigasoft Co., Ltd, there is no out-of-the-box control that provides simple and straightforward 2D data visualization based on GDI+. The NtGraph ActiveX control by Nikolai Teofilov ( inspired me to write my own control, mostly because I wanted to customize the source code when needed. Over time, the functionality of the ActiveX control became more elaborate, and finally I made a decision to publish what I have in hand under LGPL v3 license.

What Can It Do?

The control is able to plot a large number of points and update one or more plots on the graph with new data, replacing the old plot with the new plot. Multiple plots with individual properties such as color, visible could be customized at runtime.

How To Use the Control 

To use this OCX control, embed it in an application that supports the use of OCX controls. Microsoft Visual Basic applications, Office applications and applications created with the Microsoft Developer Studio's AppWizard can support the use of OCX controls. There are two files required to use this control. They are:

  • GDIPlusPlot.ocx——The GDIPlusPlot controls code and data
  • gdiplus.dll——The GDI+ dynamic linker library by Microsoft

Before the ActiveX control can be used in your application, it must be registered as a COM Component in the system registry. This is a self registering control. This means that to register the control in the system registry, you only need to have an application load the control and call the control's exported function DllRegisterServer. You can use the REGSVR32 utility or have your setup program do this.

How to Use the REGSVR32 Utility?

Copy GDIPlusPlot.ocx to your directory and type:
regsvr32 GDIPlusPlot.ocx
regsvr32 /u GDIPlusPlot.ocx (Unregister server)

Customizing the Control

You can include the control in your project by following the standard steps for ActiveX controls:

  1. Create MFC Dialog project or MDI/SDI project with View class derived from CFormView
  2. Choose menu Project|Add To Project|Components and Controls...
  3. Open the Registered ActiveX Control gallery
  4. Choose the GDIPlusPlot Control and click Insert 
  5. Visual C++ will generate the class CGDIPlusPlot
  6. Then you can define variable of the type as CGDIPlusPlot

Using the Code

HelloWorld example (here m_GDIPlusPlot1 is the on-the-fly realtime control and m_GDIPlusPlot2 is the static control):

BOOL CHelloWorldDlg::OnInitDialog()
    int RANGE_MIN = -10;
    int RANGE_MAX = 10;
    unsigned int i;

    // TODO: Initial realtime GDIPlusPlot
    m_GDIPlusPlot1.AddElement(0);   // 0 stands for Gdiplus::Color Green ARGB
    m_GDIPlusPlot1.AddElement(2);   // 2 stands for Blue
    // NOTE: There are some APIs to set the X/Y axis label, but I decide to draw 
    // the full rcBounds size ActiveX control, so comment the drawing 
    // X/Y axis label routine

    // TODO: Initial static GDIPlusPlot
    m_GDIPlusPlot2.SetXTrack(TRUE); 	// Set X track mode a red cursor 
				// following the mouse cursor
    // TODO: Loading the static random datas into static GDIPlusPlot
    for (i = 0; i < 168; i++) 
        int randv = (((double) rand() / 
                         (double) RAND_MAX) * RANGE_MAX + RANGE_MIN);
	m_GDIPlusPlot2.PlotXY(i, randv, 0);
	m_GDIPlusPlot2.PlotXY(i, randv / 1.6, 1);
	m_GDIPlusPlot2.PlotXY(i, sin(randv), 2);

    // TODO: Set a timer for loading datas into realtime GDIPlusPlot
    SetTimer(1, 100, NULL);

void CHelloWorldDlg::OnTimer(UINT nIDEvent) 
    int RANGE_MIN = -6;
    int RANGE_MAX = 6;
    int randv = (((double) rand() / 
                         (double) RAND_MAX) * RANGE_MAX + RANGE_MIN);

    // TODO: Loading the on-the-fly data into realtime GDIPlusPlot
    m_GDIPlusPlot1.PlotY(randv, 0);
    m_GDIPlusPlot1.PlotY(randv * 3, 1);

GDIPlusPlot Properties

BSTR caption;
boolean xTime;
BSTR xLabel;
BSTR yLabel;
short interval;
BSTR annolabel;
boolean xTrack;


void PlotXY(double xValue, double yValue, short index);
void SetRange(double xMin, double xMax, double yMin, double yMax);
void PlotY(double newValue, short index);
void ClearGraph();
void AddElement(short color);
void IsElementVisible(short index, boolean visible);
void SetXCursorPos(double xValue);
double GetQuadrantWidth();

Points of Interest 

The NtGraph ActiveX control based on GDI by Nikolai Teofilov inspired me to write my own control, mostly because I wanted to customize the source code when needed, so I have fun with GDI+ ^_^. 


This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

Written By
China China
An individual human existence should be like a river - small at first, narrowly contained within its banks, and rushing passionately past boulders and over waterfalls. Gradually the river grows wider, the banks recede, the waters flow more quietly, and in the end, without any visible break, they become merged in the sea, and painlessly lose their individual being.

Comments and Discussions

Question控件添加到VS2010 VS2012均发生崩溃 Pin
clevercpei21-Jul-14 17:57
clevercpei21-Jul-14 17:57 
AnswerRe: 控件添加到VS2010 VS2012均发生崩溃 Pin
Leslie Zhai29-Jul-14 16:02
Leslie Zhai29-Jul-14 16:02 
Question这狗日的代码完善了就从google删除了,鄙视 Pin
Jason.LYJ5-Sep-13 19:13
professionalJason.LYJ5-Sep-13 19:13 
AnswerRe: 这狗日的代码完善了就从google删除了,鄙视 Pin
Leslie Zhai5-Sep-13 21:38
Leslie Zhai5-Sep-13 21:38 
Questionhow to get the whole files Pin
huohongfengye28-Dec-10 18:41
huohongfengye28-Dec-10 18:41 
QuestionLogarithmic display of data ? Pin
LastPub29-Sep-10 22:10
LastPub29-Sep-10 22:10 
AnswerRe: Logarithmic display of data ? Pin
Leslie Zhai30-Sep-10 13:51
Leslie Zhai30-Sep-10 13:51 
GeneralPlease look at the error when I want to plot many point such as 1200; Pin
Dujingcang26-Dec-09 17:06
Dujingcang26-Dec-09 17:06 
GeneralRe: Please look at the error when I want to plot many point such as 1200; Pin
Leslie Zhai22-Feb-10 21:12
Leslie Zhai22-Feb-10 21:12 
GeneralRe: Please look at the error when I want to plot many point such as 1200; Pin
Leslie Zhai7-Sep-13 16:11
Leslie Zhai7-Sep-13 16:11 
GeneralMy vote of 1 Pin
Country Man20-Jul-09 20:58
Country Man20-Jul-09 20:58 
GeneralRe: My vote of 1 Pin
Leslie Zhai21-Jul-09 3:04
Leslie Zhai21-Jul-09 3:04 
GeneralRe: My vote of 1 Pin
Leslie Zhai2-Aug-09 17:35
Leslie Zhai2-Aug-09 17:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.