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
/*
 *
 *	ChartAxis.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_CHARTAXIS_H__063D695C_43CF_4A46_8AA0_C7E00268E0D3__INCLUDED_)
#define AFX_CHARTAXIS_H__063D695C_43CF_4A46_8AA0_C7E00268E0D3__INCLUDED_

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

#include "ChartObject.h"
#include "ChartScrollBar.h"
#include <afx.h>

#include <string>
#include <list>

class CChartGrid;
class CChartSerie;
class CChartAxisLabel;
    
class CChartAxis : public CChartObject  
{
	friend CChartCtrl;
	friend CChartGrid;
	friend CChartSerie;
	friend CChartScrollBar;

public:

	enum AxisType
	{
		atStandard = 0,
		atLogarithmic,
		atDateTime
	};
	void	 SetAxisType(AxisType Type);
	AxisType GetAxisType() const		 { return m_AxisType; }

	enum TimeInterval
	{
		tiSecond,
		tiMinute,
		tiHour,
		tiDay,
		tiMonth,
		tiYear
	};
	void   SetDateTimeIncrement(bool bAuto, TimeInterval Interval, int Multiplier);
	void   SetTickIncrement(bool bAuto, double Increment);
	double GetTickIncrement() const  { return m_TickIncrement; }

	void SetDateTimeFormat(bool bAutomatic, std::string strFormat);

	int GetPosition();

	void SetInverted(bool bNewValue);
	bool IsInverted() const  { return m_bIsInverted; }
	void SetLogarithmic(bool bNewValue) 
	{ 
		if (bNewValue)
			m_AxisType = atLogarithmic; 
		else
			m_AxisType = atStandard;
		RefreshAutoAxis();
	}
	bool IsLogarithmic() const          { return (m_AxisType == atLogarithmic); }
	void SetAutomatic(bool bNewValue);  
	bool IsAutomatic()  const  { return m_bIsAutomatic; }

	void SetMinMax(double Minimum, double Maximum);
	void GetMinMax(double& Minimum, double& Maximum) const
	{
		Minimum = m_MinValue;
		Maximum = m_MaxValue;
	}

    long   ValueToScreen(double Value) const;
    double ScreenToValue(long ScreenVal) const;
  
	void	 SetTextColor(COLORREF NewColor);
	COLORREF GetTextColor() const			  { return m_TextColor;		}

	void SetFont(int nPointSize,std::string  strFaceName);

	CChartAxisLabel* GetLabel() const  { return m_pAxisLabel; }
	CChartGrid*		 GetGrid()	const  { return m_pAxisGrid;  }

	CChartAxis(CChartCtrl* pParent,bool bHoriz);
	virtual ~CChartAxis();

	void SetMarginSize(bool bAuto, int iNewSize);

	void SetPanZoomEnabled(bool bEnabled) { m_bZoomEnabled = bEnabled; }
	void SetZoomLimit(double dLimit)   { m_dZoomLimit = dLimit; }

	void ShowScrollBar(bool bShow);
	bool IsScrollBarVisible() const  
	{ 
		if (m_pScrollBar)
			return (m_pScrollBar->IsWindowVisible()!=0); 
		else
			return false;
	}

private:
	void CalculateTickIncrement();
	void CalculateFirstTick();
	double GetNextTickValue(double Previous);
	CString GetTickLabel(double Tick);
	CSize GetLargestTick(CDC* pDC);
	void Recalculate();
	COleDateTime AddMonthToDate(const COleDateTime& Date, int iMonthsToAdd);
	void DrawLabel(CDC* pDC);
	void RefreshDTTickFormat();

	void PanAxis(long PanStart, long PanEnd);
	void SetZoomMinMax(double Minimum, double Maximum);
	void UndoZoom();

	void SetDecimals(int NewValue)  { m_DecCount = NewValue; }
	bool IsHorizontal() const  { return m_bIsHorizontal; }

    int  GetAxisLenght() const;
	void SetSecondary(bool bNewVal)  { m_bIsSecondary = bNewVal; }
	bool GetSecondary() const		 { return m_bIsSecondary; }

	bool RefreshAutoAxis();
	void GetSeriesMinMax(double& Minimum, double& Maximum);

	void SetAxisSize(CRect ControlRect,CRect MarginRect);
	int ClipMargin(CRect ControlRect,CRect& MarginRect,CDC* pDC);	// Allows to calculate the margin required to displayys ticks and text

	void Draw(CDC* pDC);

	// To register/Unregister series related to this axis
	void RegisterSeries(CChartSerie* pSeries);
	void UnregisterSeries(CChartSerie* pSeries);

	void CreateScrollBar();
	void UpdateScrollBarPos();
	void RefreshScrollBar();


	AxisType m_AxisType;		// Type of the axis (standard, log or date/time)

	bool m_bIsHorizontal;	  // Indicates if this is an horizontal or vertical axis
	bool m_bIsInverted;		  // Indicates if the axis is inverted
	bool m_bIsAutomatic;      // Indicates if the axis is automatic

	bool m_bIsSecondary;	// If the axis is secondary, it will be positioned to 
                            // the right (vertical) or to the top (horizontal)
	double m_MaxValue;		// Maximum value on the axis
	double m_MinValue;		
	double m_UnzoomMin;		// Min and max values of the axis before it has been zoomed
	double m_UnzoomMax;		// (used when we unzoom the chart -> go back to previous state)

	bool   m_bAutoTicks;		// Specify if the tick increment is manual or automatic
	double m_TickIncrement;		// Indicates the space between ticks (in axis value) or for log axis the mult base between two ticks
	double m_FirstTickVal;

	unsigned int m_DecCount;	// Number of decimals to display
	int m_StartPos;			    // Start position of the axis 
	int m_EndPos;

	int  m_nFontSize;			
	std::string m_strFontName;

	CChartGrid*			m_pAxisGrid;
	CChartAxisLabel*	m_pAxisLabel;

	typedef std::list<CChartSerie*> SeriesList;
	SeriesList m_pRelatedSeries;		// List containing pointers to series related to this axis

	// The user can specify the size of the margin, instead of
	// having it calculated automatically
	bool m_bAutoMargin;
	int m_iMarginSize;

	COLORREF m_TextColor;

	// Data for the date/time axis type.
	std::string m_strDTTickFormat;		// Format of the date/time tick labels
	bool m_bAutoTickFormat;
	TimeInterval m_BaseInterval;
	int m_iDTTickIntervalMult;

	bool m_bZoomEnabled;
	double m_dZoomLimit;

	CChartScrollBar* m_pScrollBar;
};

#endif // !defined(AFX_CHARTAXIS_H__063D695C_43CF_4A46_8AA0_C7E00268E0D3__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
Web02 | 2.8.140922.1 | Last Updated 13 Jul 2010
Article Copyright 2006 by Cedric Moonen
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid