Click here to Skip to main content
15,861,125 members
Articles / Desktop Programming / MFC

High-speed Charting Control

Rate me:
Please Sign up or sign in to vote.
4.95/5 (327 votes)
13 Jul 2010CPOL35 min read 4.1M   99.5K   787  
A flexible charting control to display 2D data
/*
 *
 *	ChartSurfaceSerie.h
 *
 *	Written by C�dric Moonen (cedric_moonen@hotmail.com)
 *
 *
 *
 *	This code may be used for any non-commercial and commercial purposes in a compiled form.
 *	The code may be redistributed as long as it remains unmodified and providing that the 
 *	author name and this disclaimer remain intact. The sources can be modified WITH the author 
 *	consent only.
 *	
 *	This code is provided without any garanties. I cannot be held responsible for the damage or
 *	the loss of time it causes. Use it at your own risks
 *
 *	An e-mail to notify me that you are using this code is appreciated also.
 *
 *
 */

#if !defined(AFX_CHARTSURFACESERIE_H__28A77823_43BD_4502_9AA7_A2B227454035__INCLUDED_)
#define AFX_CHARTSURFACESERIE_H__28A77823_43BD_4502_9AA7_A2B227454035__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "ChartXYSerie.h"

//! Specialization of a CChartSerie to display a surface series.
/**
	A surface can be horizontal (default) or vertical: this defines how 
	the filling of the surface is done. For a horizontal surface, the 
	filling is done between the points and the associated horizontal axis 
	and for a vertical surface, the filling is done between the points 
	and the associated vertical axis. 
	The series can be associated with a secondary axis. For example, if 
	the surface series is horizontal and is associated with the top axis 
	(secondary axis), the filling is done between the top axis and the points.
**/
class CChartSurfaceSerie : public CChartXYSerie  
{
public:
	//! Constructor
	CChartSurfaceSerie(CChartCtrl* pParent);
	//! Destructor
	virtual ~CChartSurfaceSerie();

	//! The different fill styles
	enum FillStyle
	{
		fsSolid = 0,
		fsHatchDownDiag,
		fsHatchUpDiag,
		fsHatchCross,
		fsHatchDiagCross,
		fsHatchHorizontal,
		fsHatchVertical
	};

	//! Sets the fill style
	void SetFillStyle(FillStyle NewStyle);
	//! Returns the fill style
	FillStyle GetFillStyle() const		   { return m_FillStyle; }

	//! Sets the series in horizontal or vertical mode
	/**
		If the series is in horizontal mode, the filling will be done between
		the data points and the horizontal axis.
	**/
	void SetHorizontal(bool bHoriz);
	//! Returns true if the series is in horizontal mode
	bool GetHorizontal() const		{ return m_bHorizontal;   }

	//! Check whether a screen point is on the series.
	/**
		This function returns true if the screen point is on the surface.
		If the screen point is also close to a specific point of the series, the
		index of the point is stored in the uIndex parameter. Otherwise, this 
		parameter contains INVALID_POINT.
		@param screenPoint
			The screen point to test
		@param uIndex
			If the point is close to a specific point of the series, its index is stored here.
		@return true if the point is on the series
	**/
	bool IsPointOnSerie(const CPoint& screenPoint, unsigned& uIndex) const; 

	void CChartSurfaceSerie::SetSeriesOrdering(PointsOrdering );
private:
	//! Override in order to avoid changing series ordering.
//	void SetSeriesOrdering(CChartPointsArray::PointsOrdering);

	//! Draws the legend icon for the series.
	/**
		This pure virtual function should be overriden by child classes.
		@param pDC
			The device context used to draw
		@param rectBitmap
			The rectangle in which to draw the legend icon
	**/
    void DrawLegend(CDC* pDC, const CRect& rectBitmap) const;

	//! Draws the most recent points of the series.
	/**
		This pure virtual function should be overriden by child classes.
		This function should only draw the points that were not previously 
		drawn.
		@param pDC
			The device context used to draw
	**/
	void Draw(CDC* pDC);
	//! Redraws the full series.
	/**
		This pure virtual function should be overriden by child classes.
		@param pDC
			The device context used to draw
	**/
	void DrawAll(CDC *pDC);

	//! The brush style used to fill the surface
	FillStyle m_FillStyle;
	//! The horizontal/vertical mode
	bool m_bHorizontal;
};

#endif // !defined(AFX_CHARTSURFACESERIE_H__28A77823_43BD_4502_9AA7_A2B227454035__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
Belgium Belgium
I am a 29 years old guy and I live with my girlfriend in Hoegaarden, little city from Belgium well known for its white beer Smile | :) .
I studied as an industrial engineer in electronics but I oriented myself more towards software development when I started to work.
Currently I am working in a research centre in mechatronica. I mainly develop in C++ but I also do a bit of Java.
When I have so spare time, I like to read (mainly fantasy) and play electric guitar.

Comments and Discussions