Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

High-speed Charting Control

, 13 Jul 2010
A flexible charting control to display 2D data
chartcrtl_src.zip
ChartCtrl_demo.zip
ChartDemo
ChartCtrl
.svn
all-wcprops
entries
format
prop-base
props
text-base
ChartAxis.cpp.svn-base
ChartAxis.h.svn-base
ChartAxisLabel.cpp.svn-base
ChartAxisLabel.h.svn-base
ChartBalloonLabel.h.svn-base
ChartBalloonLabel.inl.svn-base
ChartBarSerie.cpp.svn-base
ChartBarSerie.h.svn-base
ChartCandlestickSerie.cpp.svn-base
ChartCandlestickSerie.h.svn-base
ChartCrossHairCursor.cpp.svn-base
ChartCrossHairCursor.h.svn-base
ChartCtrl.cpp.svn-base
ChartCtrl.h.svn-base
ChartCursor.cpp.svn-base
ChartCursor.h.svn-base
ChartDateTimeAxis.cpp.svn-base
ChartDateTimeAxis.h.svn-base
ChartDragLineCursor.cpp.svn-base
ChartDragLineCursor.h.svn-base
ChartFont.cpp.svn-base
ChartFont.h.svn-base
ChartGanttSerie.cpp.svn-base
ChartGanttSerie.h.svn-base
ChartGradient.cpp.svn-base
ChartGradient.h.svn-base
ChartGrid.cpp.svn-base
ChartGrid.h.svn-base
ChartLabel.h.svn-base
ChartLabel.inl.svn-base
ChartLegend.cpp.svn-base
ChartLegend.h.svn-base
ChartLineSerie.cpp.svn-base
ChartLineSerie.h.svn-base
ChartLogarithmicAxis.cpp.svn-base
ChartLogarithmicAxis.h.svn-base
ChartMouseListener.h.svn-base
ChartPointsArray.h.svn-base
ChartPointsArray.inl.svn-base
ChartPointsSerie.cpp.svn-base
ChartPointsSerie.h.svn-base
ChartScrollBar.cpp.svn-base
ChartScrollBar.h.svn-base
ChartSerie.cpp.svn-base
ChartSerie.h.svn-base
ChartSerieBase.h.svn-base
ChartSerieBase.inl.svn-base
ChartSeriesMouseListener.h.svn-base
ChartStandardAxis.cpp.svn-base
ChartStandardAxis.h.svn-base
ChartString.h.svn-base
ChartSurfaceSerie.cpp.svn-base
ChartSurfaceSerie.h.svn-base
ChartTitle.cpp.svn-base
ChartTitle.h.svn-base
ChartXYSerie.cpp.svn-base
ChartXYSerie.h.svn-base
PointsOrdering.h.svn-base
tmp
prop-base
props
text-base
ChartBalloonLabel.inl
ChartCtrl_source.zip
ChartLabel.inl
ChartPointsArray.inl
ChartSerieBase.inl
ChartDemo.dsp
ChartDemo.dsw
ColourPicker
.svn
entries
format
prop-base
props
text-base
ColourPicker.cpp.svn-base
ColourPicker.h.svn-base
ColourPopup.cpp.svn-base
ColourPopup.h.svn-base
tmp
prop-base
props
text-base
Doc
html
class_c_chart_axis.png
class_c_chart_balloon_label.png
class_c_chart_bar_serie.png
class_c_chart_candlestick_serie.png
class_c_chart_cross_hair_cursor.png
class_c_chart_cursor.png
class_c_chart_date_time_axis.png
class_c_chart_drag_line_cursor.png
class_c_chart_gantt_serie.png
class_c_chart_label.png
class_c_chart_line_serie.png
class_c_chart_logarithmic_axis.png
class_c_chart_points_serie.png
class_c_chart_serie.png
class_c_chart_serie_base.png
class_c_chart_standard_axis.png
class_c_chart_surface_serie.png
class_c_chart_x_y_serie.png
doxygen.png
tab_b.gif
tab_l.gif
tab_r.gif
res
ChartDemo.ico
ChartCtrl_doxygen.zip
html
class_c_chart_axis.png
class_c_chart_balloon_label.png
class_c_chart_bar_serie.png
class_c_chart_candlestick_serie.png
class_c_chart_cross_hair_cursor.png
class_c_chart_cursor.png
class_c_chart_date_time_axis.png
class_c_chart_drag_line_cursor.png
class_c_chart_gantt_serie.png
class_c_chart_label.png
class_c_chart_line_serie.png
class_c_chart_logarithmic_axis.png
class_c_chart_points_serie.png
class_c_chart_serie.png
class_c_chart_serie_base.png
class_c_chart_standard_axis.png
class_c_chart_surface_serie.png
class_c_chart_x_y_serie.png
doxygen.png
tab_b.gif
tab_l.gif
tab_r.gif
ChartCtrl_source.zip
ChartLabel.inl
ChartPointsArray.inl
ChartSerieBase.inl
ChartBalloonLabel.inl
chartctrl_src.zip
chartctr_demo.zip
ChartDemo.clw
ChartDemo.dsp
ChartDemo.dsw
res
ChartDemo.ico
/*
 *
 *	ChartLegend.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_CHARTLEGEND_H__CD72E5A0_8F52_472A_A611_C588F642080B__INCLUDED_)
#define AFX_CHARTLEGEND_H__CD72E5A0_8F52_472A_A611_C588F642080B__INCLUDED_

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

#include "ChartCtrl.h"

#include "ChartString.h"

class CChartSerie;

//! This class is responsible for the legend displayed on the control.
/**
	Series which are named will be displayed in the legend. The legend
	object is retrieved	by calling the GetLegend() function on the 
	CChartCtrl class. 
**/
class CChartLegend  
{
	friend CChartCtrl;

public:
	//! Sets the font used to display the series names.
	void SetFont(int iPointSize, const TChartString& strFaceName);

	//! Enumeration specifying on which side of the control the legend is docked.
	enum DockSide
	{
		dsDockRight,
		dsDockLeft,
		dsDockTop,
		dsDockBottom
	};

	//! Dock the legend on a specific side of the control. Default is right.
	void DockLegend(DockSide dsSide);
	//! Undock the legend.
	/**
		When the legend is undocked (floating), it doesn't take any margin size
		but is drawn on top of the control at the specified location (it can be
		above the plotting area for instance).
		@param iLeftPos
			The left position of the legend, in pixels (from the left of the control)
		@param iTopPos
			The top position of the legend, in pixels (from the top of the control)
	**/
	void UndockLegend(int iLeftPos, int iTopPos);

	//! Sets the background of the legend transparent.
	void SetTransparent(bool bTransparent);  
	//! Sets the legend in horizontal/vertical mode.
	/**
		In horizontal mode, the names are drawn next to each other
		instead of on top of each other.
	**/
	void SetHorizontalMode(bool bHorizontal);

	//! Sets the legend visible/invisible.
	void SetVisible(bool bVisible);
	//! Returns true if the legend is visible.
	bool IsVisible()  const         { return m_bIsVisible; }

	//! Returns the back color of the legend.
	COLORREF GetBackColor() const			   { return m_BackColor; }
	//! Sets the back color of the legend.
	void SetBackColor(COLORREF NewColor);
	//! Returns the shadow color.
	COLORREF GetShadowColor() const		   { return m_ShadowColor; }
	//! Sets the shadow color.
	void SetShadowColor(COLORREF NewColor);
	//! Enables/disables the shadow.
	void EnableShadow(bool bEnable);
	//! Sets the shadow depth (in pixels).
	void SetShadowDepth(int Depth);

	//! Returns true if the screen point is on the legend region.
	BOOL IsPointInside(const CPoint& screenPoint) const;

private:
	//! Constructor
	CChartLegend(CChartCtrl* pParent);
	//! Destructor
	virtual ~CChartLegend();

	//! Draw the legend.
	void Draw(CDC* pDC);
	//! Remove the area needed for the legend from the chart rectangle.
	void ClipArea(CRect& rcControl, CDC* pDC);
	//! Recalculate the legend size and position.
	void UpdatePosition(CDC* pDC, const CRect& rcControl);

	//! The parent charting control.
	CChartCtrl* m_pParentCtrl;
	//! The rectangle used to draw the legend.
	CRect m_LegendRect;

	//! The font face name used to display the series names.
	TChartString m_strFontName;
	//! The font point size.
	int          m_iFontSize;

	//! True if the legend is docked
	bool m_bDocked;	
	//! The side of the control on which the legend is docked.
	DockSide m_DockSide;

	//! The left position of the legend if in floating mode.
	int m_iLeftPos;
	//! The top position of the legend if in floating mode.
	int m_iTopPos;

	//! Specifies if the legend is visible.
	bool m_bIsVisible;
	//! Specifies if the background of the legend is transparent.
	bool m_bIsTransparent;
	//! Specifies if the legend is in horizontal mode.
	bool m_bIsHorizontal;
	//! Specifies if the legend shadow should be displayed.
	bool m_bShadow;
	//! Specifies the shadow depth (in pixels).
	int m_iShadowDepth;

	//! Specifies the legend back color.
	COLORREF m_BackColor;
	//! Specifies the shadow color.
	COLORREF m_ShadowColor;

	//! Specifies the size of the bitmap used by each series.
	CSize m_BitmapSize;
};

#endif // !defined(AFX_CHARTLEGEND_H__CD72E5A0_8F52_472A_A611_C588F642080B__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)

Share

About the Author

Cedric Moonen
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.

| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 13 Jul 2010
Article Copyright 2006 by Cedric Moonen
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid