Click here to Skip to main content
15,887,135 members
Articles / Desktop Programming / MFC
Article

Scientific charting control

Rate me:
Please Sign up or sign in to vote.
4.84/5 (122 votes)
17 Jan 20055 min read 1.3M   42.6K   405   380
Multi-purpose scientific charting control.

Image 1

Image 2

Image 3

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

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

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


Written By
Web Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Saved Graph Pin
Anonymous23-Sep-02 1:49
Anonymous23-Sep-02 1:49 
GeneralUpdate Pin
Gunnar Bolle19-Sep-02 0:01
Gunnar Bolle19-Sep-02 0:01 
GeneralRe: Update Pin
Bedi9-Dec-02 21:01
Bedi9-Dec-02 21:01 
GeneralRe: Update Pin
min_2_max12-Dec-02 3:53
min_2_max12-Dec-02 3:53 
GeneralProblem changing axis ranges & step size Pin
Rex Kerr13-Sep-02 20:34
sussRex Kerr13-Sep-02 20:34 
GeneralProgram hangs. Builds with no error or warnings Pin
Alton10013-Sep-02 6:50
Alton10013-Sep-02 6:50 
GeneralRe: Program hangs. Builds with no error or warnings Pin
Anonymous18-Sep-02 23:31
Anonymous18-Sep-02 23:31 
GeneralSolution Pin
Anonymous18-Sep-02 23:58
Anonymous18-Sep-02 23:58 
GeneralProblems with upgrading the project for VC++7 Pin
Anonymous12-Sep-02 0:17
Anonymous12-Sep-02 0:17 
GeneralFlickering when resizing Pin
Acreff3-Sep-02 20:14
Acreff3-Sep-02 20:14 
GeneralRe: Flickering when resizing Pin
3-Sep-02 21:30
suss3-Sep-02 21:30 
GeneralMissing data point in display Pin
cfedor20-Aug-02 10:57
cfedor20-Aug-02 10:57 
GeneralRe: Missing data point in display Pin
Xiong Jianjun20-Aug-02 18:21
Xiong Jianjun20-Aug-02 18:21 
GeneralPint Pin
Xiong Jianjun11-Aug-02 20:22
Xiong Jianjun11-Aug-02 20:22 
GeneralRe: Print Pin
cfedor20-Aug-02 11:04
cfedor20-Aug-02 11:04 
GeneralRe: Print Pin
Xiong Jianjun20-Aug-02 14:32
Xiong Jianjun20-Aug-02 14:32 
Generaly Axis for small doubles Pin
Cuba24-Jul-02 20:56
Cuba24-Jul-02 20:56 
GeneralInsert in modal dialog Pin
Anonymous11-Jul-02 1:45
Anonymous11-Jul-02 1:45 
GeneralRe: Insert in modal dialog Pin
Rex Kerr13-Sep-02 20:43
sussRex Kerr13-Sep-02 20:43 
GeneralRe: Insert in modal dialog Pin
MartinG5-Mar-03 23:10
MartinG5-Mar-03 23:10 
GeneralRe: Insert in modal dialog Pin
Rex Kerr6-Mar-03 5:58
sussRex Kerr6-Mar-03 5:58 
GeneralCrash on left dbl click Pin
niklo5-Jul-02 3:51
niklo5-Jul-02 3:51 
GeneralRe: Crash on left dbl click Pin
Gunnar Bolle8-Jul-02 1:07
Gunnar Bolle8-Jul-02 1:07 
GeneralRe: Crash on left dbl click Pin
XiongJianjun10-Jul-02 15:48
XiongJianjun10-Jul-02 15:48 
GeneralRe: Crash on left dbl click Pin
Anonymous18-Apr-05 5:02
Anonymous18-Apr-05 5:02 

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.