Click here to Skip to main content
15,880,469 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.2M   100.4K   787  
A flexible charting control to display 2D data
/*
 *
 *	ChartBalloonLabel.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.
 *
 *
 */

#ifndef _CHARTBALLOONLABEL_H_ 
#define _CHARTBALLOONLABEL_H_

#include "ChartLabel.h"
#include "ChartFont.h"

//! Specialization of the CChartLabel to display a balloon label.
/**
	A balloon label is a label with a rounded rectangle area in which the 
	text is displayed and which is connected with a line to the point to
	which it is attached.
**/
template <class PointType>
class CChartBalloonLabel : public CChartLabel<PointType>
{
	friend CChartSerieBase<PointType>;

public:
	//! Sets the background color of the text area.
	void SetBackgroundColor(COLORREF colBackground);
	//! Retrieves the background color of the text area.
	COLORREF GetBackgroundColor() const		{ return m_colBackground; }
	//! Sets the color of the line connecting the point to the text area.
	void SetLineColor(COLORREF colArrow);	
	//! Retrieves the color of the line connecting the point to the text area.
	COLORREF GetLineColor() const			{ return m_colLine; }
	//! Sets the color of border's text area.
	void SetBorderColor(COLORREF colBorder);
	//! Retrieves the color of border's text area.
	COLORREF GetBorderColor() const			{ return m_colBorder; }

	//! Specifies if the text area is rounded or not.
	void SetRoundedRect(bool bRounded);
	//! Returns true if the text area is rounded.
	bool GetRoundedRect() const		{ return m_bRoundedRect; }

	//! Sets the font of the text.
	/**
		@param nPointSize
			The font point size.
		@param strFaceName
			The font face name ("Times New Roman", "Arial", ...)
	**/
	void SetFont(int nPointSize, const TChartString& strFaceName);
	//! Sets the font of the text.
	/**
		This function allows to set extended font style by passing
		a CChartFont object.
		@param newFont
			The new font.
	**/
	void SetFont(const CChartFont& newFont);

	//! Constructor
	CChartBalloonLabel(CChartCtrl* pParentCtrl, CChartSerieBase<PointType>* pParentSeries);
	//! Destructor
	~CChartBalloonLabel();

protected:
	//! Draw the label.
	void Draw(CDC* pDC, unsigned uPointIndex);

private:
	//! Color of the liune connecting the point to the text area.
	COLORREF m_colLine;
	//! Color of the text area's background.
	COLORREF m_colBackground;
	//! Color of border's text area.
	COLORREF m_colBorder;

	//! The font used for the text label.
	CChartFont m_Font;

	//! Specifies if the rectangle is rounded or not.
	bool m_bRoundedRect;
};

#include "ChartBalloonLabel.inl"

#endif  // _CHARTBALLOONLABEL_H_

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