Click here to Skip to main content
11,701,855 members (65,255 online)
Click here to Skip to main content

Scientific charting control

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

Introduction

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.

Features

  • 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

Classes

CXGraph

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.

CXGraphLabel

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

CXGraphAxis

See source code

CXGraphDataSerie

See source code

Notifications

  • XG_YAXISCLICK
  • XG_XAXISCLICK
  • XG_CURVECLICK
  • XG_YAXISDBLCLICK
  • XG_XAXISDBLCLICK
  • XG_CURVEDBLCLICK
  • XG_GRAPHDBLCLICK
  • XG_RBUTTONUP
  • XG_CURSORMOVED

Usage

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.

Credits

  • 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

Date Version Comment
21 Mar 2002 1.00
  • First release.
25 Mar 2002 1.01
  • Fixed DateTime-bug in cursor mode.
  • Fixed crash when adding trend or moving average.
17 Apr 2002 1.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 2002 1.03
  • Now compiles under VC7.
  • Load/save for properties/data/object persistence.
  • Lots of bug fixes.
20 Nov 2003 1.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 2005 1.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.

License

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

Share

About the Author

Gunnar Bolle
Web Developer
Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionC# wrapper Pin
Joel Smit22-Nov-13 2:21
memberJoel Smit22-Nov-13 2:21 
QuestionLink with VS2008 Pin
CynthiaLiu17-Oct-13 22:18
memberCynthiaLiu17-Oct-13 22:18 
AnswerRe: Link with VS2008 Pin
phonio25-May-15 5:22
professionalphonio25-May-15 5:22 
QuestionAccuracy of Graphs Pin
sseredn25-Feb-13 18:59
membersseredn25-Feb-13 18:59 
QuestionCompiling with Visual Studio 2010 Pin
Member 786633813-Dec-12 22:44
memberMember 786633813-Dec-12 22:44 
AnswerRe: Compiling with Visual Studio 2010 Pin
soft_raider5-Jun-13 2:26
membersoft_raider5-Jun-13 2:26 
GeneralRe: Compiling with Visual Studio 2010 Pin
CynthiaLiu17-Oct-13 20:06
memberCynthiaLiu17-Oct-13 20:06 
QuestionHow can I put text labels on an axis? Pin
Tom Paronis31-Oct-12 12:50
memberTom Paronis31-Oct-12 12:50 
QuestionLicense Pin
Yusein Ali28-Feb-12 22:57
memberYusein Ali28-Feb-12 22:57 
AnswerRe: License Pin
xawari29-Oct-12 4:56
memberxawari29-Oct-12 4:56 
GeneralRe: License Pin
Tom Paronis1-Nov-12 5:56
memberTom Paronis1-Nov-12 5:56 
GeneralRe: License Pin
xawari18-Nov-12 3:46
memberxawari18-Nov-12 3:46 
GeneralRe: License Pin
Tom Paronis18-Nov-12 5:59
memberTom Paronis18-Nov-12 5:59 
Suggestionlook here for UPDATED sources! Pin
xawari20-Feb-12 6:54
memberxawari20-Feb-12 6:54 
GeneralRe: look here for UPDATED sources! Pin
phonio25-May-15 15:52
professionalphonio25-May-15 15:52 
Question64 bit compatibility ? Pin
beauwlf12-Jul-11 23:02
memberbeauwlf12-Jul-11 23:02 
GeneralMy vote of 5 Pin
bigbigmonkey17-May-11 22:37
memberbigbigmonkey17-May-11 22:37 
GeneralExcellent Pin
sisixiao12-Mar-11 15:35
membersisixiao12-Mar-11 15:35 
Generalquestion on your trending algorithms Pin
Michael Eber24-Jun-10 5:28
memberMichael Eber24-Jun-10 5:28 
QuestionHow To Port The Control To WINDOWS CE Pin
ten319830-May-10 16:21
memberten319830-May-10 16:21 
GeneralXGraph von Codeproject.com lässt sich nicht übersetzen Pin
HSCH_20106-Mar-10 0:47
memberHSCH_20106-Mar-10 0:47 
GeneralVS2008 problem.....help me, please. Pin
Seungkwon Kim21-Dec-09 17:52
memberSeungkwon Kim21-Dec-09 17:52 
GeneralRe: VS2008 problem.....help me, please. Pin
Jack Lu18-May-10 22:29
memberJack Lu18-May-10 22:29 
QuestionIs This support Bar Graph ? or any plan for support Bar Graph ? Pin
gsheladia16-Dec-09 6:16
membergsheladia16-Dec-09 6:16 
GeneralCompile under vs2005 Pin
maruigxxg10-Dec-09 20:18
membermaruigxxg10-Dec-09 20:18 
GeneralRe: Compile under vs2005 Pin
xicexice12-Apr-11 17:13
memberxicexice12-Apr-11 17:13 
GeneralRe: Compile under vs2005 Pin
bobhappy826-Jul-11 16:19
memberbobhappy826-Jul-11 16:19 
GeneralRe: Compile under vs2005 Pin
misasagi_inori12-Dec-11 14:26
membermisasagi_inori12-Dec-11 14:26 
GeneralRe: Compile under vs2005 Pin
noending18-Nov-12 19:27
membernoending18-Nov-12 19:27 
GeneralRe: Compile under vs2005 Pin
Member 1130889714-Dec-14 0:32
memberMember 1130889714-Dec-14 0:32 
GeneralRe: Compile under vs2005 Pin
phonio25-May-15 3:28
professionalphonio25-May-15 3:28 
GeneralA probable bug concerning autoscaling Pin
didov22-Jul-09 6:27
memberdidov22-Jul-09 6:27 
GeneralPrinting!! Pin
dd-pp-qq6-May-09 16:05
memberdd-pp-qq6-May-09 16:05 
GeneralCompiling under VS2008 or VS2005 Pin
srjacob23-Apr-09 9:56
membersrjacob23-Apr-09 9:56 
GeneralRe: Compiling under VS2008 or VS2005 Pin
misasagi_inori12-Dec-11 14:27
membermisasagi_inori12-Dec-11 14:27 
GeneralThanks... Pin
Dan Bloomquist9-Apr-09 19:01
memberDan Bloomquist9-Apr-09 19:01 
QuestionHi XGraph is supporting vs 2005 ? Pin
gsheladia16-Mar-09 23:34
membergsheladia16-Mar-09 23:34 
AnswerRe: Hi XGraph is supporting vs 2005 ? Pin
maruigxxg10-Dec-09 19:07
membermaruigxxg10-Dec-09 19:07 
QuestionUsing chart in VB6 Pin
sd737327-Oct-07 12:20
membersd737327-Oct-07 12:20 
QuestionPrinting!!?? Pin
sritter13-Sep-07 4:43
membersritter13-Sep-07 4:43 
Generalbug fixed: CXGraph::Autoscale() doesn't work Pin
hamo20081-Sep-07 0:58
memberhamo20081-Sep-07 0:58 
GeneralUNSTABLE! -- fixed release Pin
xawari12-Aug-07 5:52
memberxawari12-Aug-07 5:52 
GeneralRe: UNSTABLE! -- fixed release Pin
geoyar23-Aug-07 15:04
membergeoyar23-Aug-07 15:04 
GeneralRe: UNSTABLE! -- fixed release Pin
Razmar11-Aug-08 7:01
memberRazmar11-Aug-08 7:01 
AnswerRe: UNSTABLE! -- fixed release Pin
xawari20-Aug-08 22:42
memberxawari20-Aug-08 22:42 
GeneralRe: UNSTABLE! -- fixed release Pin
Razmar20-Aug-08 22:47
memberRazmar20-Aug-08 22:47 
GeneralRe: UNSTABLE! -- fixed release Pin
Liwei.whu10-Dec-08 21:20
memberLiwei.whu10-Dec-08 21:20 
GeneralI've used in vs2008 is ok. Pin
Jack Lu24-Jan-11 20:16
memberJack Lu24-Jan-11 20:16 
GeneralRe: UNSTABLE! -- fixed release Pin
deeps198524-Jan-11 20:31
memberdeeps198524-Jan-11 20:31 
Questioncan not compile Pin
Oliver@Erb-electronics.de12-Jul-07 21:04
memberOliver@Erb-electronics.de12-Jul-07 21:04 

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

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

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