Click here to Skip to main content
13,289,626 members (59,430 online)
Click here to Skip to main content
Add your own
alternative version


387 bookmarked
Posted 20 Mar 2002

Scientific charting control

, 17 Jan 2005
Rate this:
Please Sign up or sign in to vote.
Multi-purpose scientific charting control.


Displaying large amounts of technical data in a chart can be a frustrating task. You can find tons of charting controls with fancy effects and useless features, but when it comes to displaying many curves at once, independently scaled on different axes, most of them fail. Maybe CXGraph is the solution:

CXGraph can display unlimited series of data on multiple axes.

The documentation is sparse, because I do not have the time to write documentation. However, the included demo is hopefully a help in understanding how to use the control.


  • unlimited data series
  • unlimited axes (your monitor is the limit)
  • logarithmic scales
  • autoscaling
  • automatic/manual axis placement
  • nearly every visual aspect can be customized
  • legends
  • bitmaps
  • cursor (add data notation marks by clicking)
  • zoom
  • pan
  • color ranges
  • object selection with the mouse
  • linear trend
  • cubic trend
  • nth order polynomial trend
  • data notation marks
  • moving average (simple, linear, sine-weighted ...)
  • property persistence (save and load properties, data and axes)
  • Support for Windows CE
  • axis markers
  • UNICODE support
  • polygon filling between curves
  • cursor synchronization
  • data editing
  • measuring mode



CXGraphDataSerie& SetData(TDataPoint* pValues, long nCount, int nCurve, int nXAxis, int nYAxis, bool bAutoDelete)Adds/sets a data series.
CXGraphAxis& GetXAxis(int nAxis)Returns reference to specified X-axis.
CXGraphAxis& GetYAxis(int nAxis)Returns reference to specified y-axis.
CXGraphDataSerie& GetCurve(int nCurve)Returns reference to specified curve.
bool SelectCurve(int nCurve)Selects the specified curve.
bool SelectXAxis(int nAxis)Selects the specified x-axis.
bool SelectYAxis(int nAxis)Selects the specified y-axis.
int GetXAxisCount()Returns x-axis count.
int GetYAxisCount()Returns y-axis count.
int GetCurveCount()Returns curve count.
void Zoom()Zoom-mode. User can zoom into the graph with the mouse.
void ResetZoom()Resets all axes to optimal values.
void Pan()Pan-mode. User can pan the graph with the mouse.
void NoOp()Select-mode. User can select objects with the mouse.
void Cursor()Cursor-mode. A cursor is being displayed showing the values at the current mouse position.
void Measure()Measuring mode. User can measure the distance between two data points.
void Edit()Editing mode. User can edit the curve data.
CXGraphLabel& InsertLabel(CString cText)Inserts a text-label. Returns reference to a CXGraphLabel object.
void PrintGraph(CDC *pDC)Prints the graph.
void SetBackColor(COLORREF color)Sets the chart's backcolor.
void SetGraphColor(COLORREF color)Sets the chart's exterior color.
void SetInnerColor(COLORREF color)Sets the chart's interior color.
void SetDoubleBuffer(bool bValue)Sets double buffering on/off.
void SetShowLegend(bool bValue)Sets legend display on/off.
void SetLegendAlignment(EAlignment align)Sets the legend alignment (left, right).
void SetSnapCursor(bool bValue)Sets snap cursor mode (on/off).
void SetInteraction(bool bValue)Enable/disable interaction.
bool GetInteraction()
void SetSnapRange(int nValue)Sets snap cursor range.
bool Save(const CString cFile, UINT nFlags)

Stores chart properties, data and axes. Use one or more of the following values to specify what to be stored:

  • PERSIST_PROPERTIES: store chart properties.
  • PERSIST_DATA: store chart data and axes.
  • PERSIST_OBJECTS: store chart objects (labels, ...).
bool Load(const CString cFile)Loads chart properties, data and axes.
bool SaveBitmap(const CString cFile)Saves the chart as bitmap.
bool DeleteCurve(int nCurve)Deletes the specified curve.
bool DeleteYAxis(int nAxis)Removes the specified y-axis.
bool DeleteXAxis(int nAxis)Removes the specified x-axis.
int GetZoomDepth()Determines the zoom depth (history).
void RestoreLastZoom()Restores the last zoom stage.
void SetBackgroundBitmap(CBitmap* pBitmap, UINT nFlags)Sets a background image.
void InsertBitmap(CRect rect, CBitmapEx* pBitmap)Inserts a bitmap-object.


SetFont(LOGFONT* pLogFont)Sets the label's font.
SetText(CString cText)Sets the label's text.
SetColor(COLORREF color)Sets the label's background color.
SetTextColor(COLORREF color)Sets the label's text color.
SetBorder(bool bValue)Sets the label's border.
SetTransparent(bool bValue)Sets the label's transparency.
SetAlignment(UINT nValue)Sets the label's text alignment.
SetCurve(int nCurve)Links the label to the specified curve.
CString GetText()Returns the label's text.
COLORREF GetColor()Returns the label's background color.
COLORREF GetTextColor()Returns the label's text color.
bool GetBorder()Returns true if label has a border, otherwise false.
bool GetTransparent()Returns true if label is transparent. otherwise false.
UINT GetAlignment()Returns the label's text alignment.
int GetCurve()Returns the label's associated curve (or -1 if not associated).


See source code


See source code




To use this control in your own application, add XGraph10.lib to your project and make sure XGraph10.dll is accessible. Create an instance of CXGraph and call Create on it. Take a look at the sample application for further details.


  • James White - Color button.
  • Chris Maunder, Alexander Bischofberger - Color popup.
  • Dennis Crain (MSDN) - Routines for line-hit testing.
  • Keith Rule - CMemDC.
  • Ishay Sivan (bug fixing).
  • Pavel Klocek (bug fixing).
  • J.G. Hattingh (parts of Device Context Utilities).
  • Jörg Blattner (bug fixing, improvements).

History & Bug fixes

21 Mar 20021.00
  • First release.
25 Mar 20021.01
  • Fixed DateTime-bug in cursor mode.
  • Fixed crash when adding trend or moving average.
17 Apr 20021.02
  • Panning in cursor mode added.
  • Added support for very large and very small numbers.
  • Values greater/less than 10E6/10E-6 are now automatically shown in exponential format.
  • Completely redesigned autoscaling (only for normal axes, DateTime types follow).
  • Added data notation marks.
  • Added Get/Set member functions.
  • Added nth-order-polynomial trend.
20 Sep 20021.03
  • Now compiles under VC7.
  • Load/save for properties/data/object persistence.
  • Lots of bug fixes.
20 Nov 20031.04
  • Added Unicode support.
  • Fixed crash when resizing chart to small dimensions.
  • Corrected tab-order in property pages.
  • Added background bitmaps.
  • Added gradient color ranges.
  • Added axis markers.
  • Added bitmap objects.
13 Jan 20051.05
  • Added support for Windows CE (needs improvement).
  • Logarithmic axes (thanks to ...).
  • Added polygon filling between two curves.
  • Several bugs fixed by Joerg Blattner.
  • Added Cursor-Synchronization.
  • Curve editing mode.
  • Measuring mode.

Known issues

  • Clipping in print preview still doesn't work.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Gunnar Bolle
Web Developer
Germany Germany
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionHi XGraph is supporting vs 2005 ? Pin
gsheladia17-Mar-09 0:34
membergsheladia17-Mar-09 0:34 
AnswerRe: Hi XGraph is supporting vs 2005 ? Pin
maruigxxg10-Dec-09 20:07
membermaruigxxg10-Dec-09 20:07 
QuestionUsing chart in VB6 Pin
sd737327-Oct-07 13:20
membersd737327-Oct-07 13:20 
AnswerRe: Using chart in VB6 Pin
Jack Lu26-Dec-16 19:05
memberJack Lu26-Dec-16 19:05 
QuestionPrinting!!?? Pin
sritter13-Sep-07 5:43
membersritter13-Sep-07 5:43 
Generalbug fixed: CXGraph::Autoscale() doesn't work Pin
hamo20081-Sep-07 1:58
memberhamo20081-Sep-07 1:58 
GeneralUNSTABLE! -- fixed release Pin
xawari12-Aug-07 6:52
memberxawari12-Aug-07 6:52 
GeneralRe: UNSTABLE! -- fixed release Pin
geoyar23-Aug-07 16:04
membergeoyar23-Aug-07 16:04 
GeneralRe: UNSTABLE! -- fixed release Pin
Razmar11-Aug-08 8:01
memberRazmar11-Aug-08 8:01 
AnswerRe: UNSTABLE! -- fixed release Pin
xawari20-Aug-08 23:42
memberxawari20-Aug-08 23:42 
GeneralRe: UNSTABLE! -- fixed release Pin
Razmar20-Aug-08 23:47
memberRazmar20-Aug-08 23:47 
GeneralRe: UNSTABLE! -- fixed release Pin
Liwei.whu10-Dec-08 22:20
memberLiwei.whu10-Dec-08 22:20 
GeneralI've used in vs2008 is ok. Pin
Jack Lu24-Jan-11 21:16
memberJack Lu24-Jan-11 21:16 
GeneralRe: UNSTABLE! -- fixed release Pin
deeps198524-Jan-11 21:31
memberdeeps198524-Jan-11 21:31 

I am trying to use this Charting in my project, which i am failin to do.
1. I had included the XGrapgh10.h and Dll and libary files.
2. Now i am trying to Use that XGraph object. it crashes

GeneralRe: UNSTABLE! -- fixed release Pin
Davide Spazian5-Dec-17 0:03
memberDavide Spazian5-Dec-17 0:03 
Questioncan not compile Pin
Oliver@Erb-electronics.de12-Jul-07 22:04
memberOliver@Erb-electronics.de12-Jul-07 22:04 
QuestionNew Version ? Pin
Stephane P.9-Jul-07 2:49
memberStephane P.9-Jul-07 2:49 
GeneralZooming and dates representation bugs Pin
Albert Jann3-Apr-07 6:50
memberAlbert Jann3-Apr-07 6:50 
GeneralCompile problem Pin
maladuk13-Dec-06 7:36
membermaladuk13-Dec-06 7:36 
Generalfix bug Pin
coslpumo28-Nov-06 17:16
membercoslpumo28-Nov-06 17:16 
GeneralRe: fix bug Pin
hamo200829-Aug-07 0:18
memberhamo200829-Aug-07 0:18 
GeneralPrinitng problem Pin
gsheladia10-Oct-06 15:16
membergsheladia10-Oct-06 15:16 
GeneralDrawing faild when i Used "SaveBitmap("c:\\1.bmp"); Pin
gsheladia9-Oct-06 21:32
membergsheladia9-Oct-06 21:32 
GeneralRe: Drawing faild when i Used "SaveBitmap("c:\\1.bmp"); Pin
gsheladia9-Oct-06 21:54
membergsheladia9-Oct-06 21:54 
GeneralCompiling error in debug mode Pin
gsheladia8-Oct-06 1:16
membergsheladia8-Oct-06 1:16 
GeneralRe: Compiling error in debug mode Pin
ogkv215-Oct-06 20:32
memberogkv215-Oct-06 20:32 
QuestionResizing/Zooming bug? Pin
aram_n12-Sep-06 4:39
memberaram_n12-Sep-06 4:39 
GeneralMemory Leakage! Pin
hznlm22-Aug-06 20:52
memberhznlm22-Aug-06 20:52 
GeneralRe: Memory Leakage! Pin
ogkv216-Oct-06 21:15
memberogkv216-Oct-06 21:15 
Generaldialog box Pin
mystikarts11-Jul-06 7:36
membermystikarts11-Jul-06 7:36 
GeneralRe: dialog box Pin
Sonar18-Jul-06 15:22
memberSonar18-Jul-06 15:22 
GeneralRe: dialog box Pin
mystikarts28-Jul-06 10:41
membermystikarts28-Jul-06 10:41 
GeneralRe: dialog box Pin
xawari12-Aug-07 7:48
memberxawari12-Aug-07 7:48 
GeneralRe: dialog box Pin
StoneHead19-Sep-11 20:42
memberStoneHead19-Sep-11 20:42 
GeneralThe problem of OnPaint() in XGraph.cpp Pin
Paul_Yang2410-Jul-06 3:55
memberPaul_Yang2410-Jul-06 3:55 
Question"OnLButtonDblClk " do not work? Pin
zhys6-Jul-06 2:08
memberzhys6-Jul-06 2:08 
Generalbug found:marker & curve not matched. Pin
jingtaozf22-Jun-06 18:25
memberjingtaozf22-Jun-06 18:25 
GeneralRe: bug found:marker & curve not matched. Pin
jingtaozf22-Jun-06 18:26
memberjingtaozf22-Jun-06 18:26 
GeneralSome bugs [modified] Pin
MarsV4-Jun-06 17:39
memberMarsV4-Jun-06 17:39 
Generalmissing xgraph10d.dll Pin
hello_angel24-May-06 6:55
memberhello_angel24-May-06 6:55 
GeneralRe: missing xgraph10d.dll Pin
MarsV30-May-06 18:45
memberMarsV30-May-06 18:45 
GeneralRe: missing xgraph10d.dll Pin
bruno leclerc30-Sep-06 8:39
memberbruno leclerc30-Sep-06 8:39 
GeneralRe: missing xgraph10d.dll Pin
bruno leclerc30-Sep-06 23:37
memberbruno leclerc30-Sep-06 23:37 
QuestionHow to make X-Label support time format? Pin
chaochao_cz16-Apr-06 19:10
memberchaochao_cz16-Apr-06 19:10 
GeneralDebug Dll Pin
NichEdgington14-Apr-06 6:40
memberNichEdgington14-Apr-06 6:40 
GeneralXGraphdemo use XGraph release dll error happened Pin
supportyou22-Mar-06 17:36
membersupportyou22-Mar-06 17:36 
GeneralXGraphdemo to use XGraph release dll Pin
supportyou22-Mar-06 17:35
membersupportyou22-Mar-06 17:35 
GeneralAutoscale Pin
Rene Desgagnes2-Mar-06 10:22
memberRene Desgagnes2-Mar-06 10:22 
GeneralVS2005 Pin
vilgvzvbxcc24-Feb-06 12:08
membervilgvzvbxcc24-Feb-06 12:08 
GeneralRe: VS2005 Pin
alexsurkov17-Apr-06 0:13
memberalexsurkov17-Apr-06 0:13 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 17 Jan 2005
Article Copyright 2002 by Gunnar Bolle
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid