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

High-speed Charting Control

, 13 Jul 2010 CPOL
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
/*
 *
 *	ChartXYSerie.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.
 *
 *
 */

#pragma once
#include "ChartSerieBase.h"

//! Structure containing a point data with X and Y values
struct SChartXYPoint
{
	SChartXYPoint() : X(0.0), Y(0.0)  
	{ 
		#ifndef NO_USER_DATA
		pUserData = NULL;
		#endif
	}
	SChartXYPoint(double XVal, double YVal) : X(XVal), Y(YVal)  
	{ 
		#ifndef NO_USER_DATA
		pUserData = NULL;
		#endif
	}

	double GetX() const { return X; }
	double GetY() const { return Y; }
	double GetXMin() const { return X; }
	double GetXMax() const { return X; }
	double GetYMin() const { return Y; }
	double GetYMax() const { return Y; }

	//! The point X value.
	double X;
	//! The point Y value.
	double Y;
	#ifndef NO_USER_DATA
	//! Optional user data.
	void *pUserData;
	#endif
};

//! Specialization of a CChartSerieBase for series having data with an X and an Y value.
/**
	This class is abstract and has to be implemented for specific series. It 
	already provides features which are common to all series with points having
	an X and an Y value. Examples of such series are: point series, line series,
	surface series and bar series.
**/
class CChartXYSerie : public CChartSerieBase<SChartXYPoint>
{
public:
	//! Constructor
	CChartXYSerie(CChartCtrl* pParent);
	//! Destructor
	virtual ~CChartXYSerie();

	//! Adds a single data point to the series.
	void AddPoint(double X, double Y);
	//! Adds an array of points to the series.
	/**
		Points which were already present in the series are kept.
		@param pX
			Array of X values for the points
		@param pY
			Array of Y values for the points
		@param Count
			Size of each of both arrays (number of points to add)
	**/
	void AddPoints(double* pX, double* pY, unsigned Count);
	//! Sets an array of points to the series.
	/**
		Points which were already present in the series are discarded.
		@param pX
			Array of X values for the points
		@param pY
			Array of Y values for the points
		@param Count
			Size of each of both arrays (number of points to add)
	**/
	void SetPoints(double* pX, double* pY, unsigned Count);

	//! Returns the Y value of a specific point in the series.
	double GetYPointValue(unsigned PointIndex) const;
	//! Returns the X value of a specific point in the series.
	double GetXPointValue(unsigned PointIndex) const;
	//! Sets the Y value of a specific point in the series.
	/**
		The control is refreshed to display the change.
		@param PointIndex
			The index of the points to change the Y value
		@param NewVal 
			The new Y value of the point
	**/
	void   SetYPointValue(unsigned PointIndex, double NewVal);
	//! Sets the X value of a specific point in the series.
	/**
		The control is refreshed to display the change.
		@param PointIndex
			The index of the points to change the Y value
		@param NewVal 
			The new X value of the point
	**/
	void   SetXPointValue(unsigned PointIndex, double NewVal);	
	
#ifndef NO_USER_DATA
	//! Sets user data for a specific point. 
	/**
		User data can be disabled by adding the flag NO_USER_DATA in the preprocessor
		definitions. This is usefull when you don't want to have an additional pointer
		stored for each points in your series.
	**/
	void  SetUserData(unsigned uPointIndex, void* pData);
	//! Retrieves user data for a specific point. 
	/**
		User data can be disabled by adding the flag NO_USER_DATA in the preprocessor
		definitions. This is usefull when you don't want to have an additional pointer
		stored for each points in your series.
	**/
	void* GetUserData(unsigned uPointIndex);
#endif

protected:
	//! Retrieves the control points of a bezier curve fitting the points stored in the array.
	/**
		@param uFirst
			The index of the first point of the bezier curve
		@param uLast
			The index of the last point of the bezier curve
		@param pKnots
			This parameter will store the points data
		@param pFirstControlPoints
			This parameter will store the primary control points of the bezier curve
		@param pSecondControlPoints
			This parameter will store the secondary control points of the bezier curve
	**/
	void GetBezierControlPoints(unsigned uFirst, unsigned uLast, SChartXYPoint* &pKnots,
				SChartXYPoint* &pFirstControlPoints, SChartXYPoint* &pSecondControlPoints) const;

private:
	double* GetFirstControlPoints(double* rhs, int Count) const;
};

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 | Terms of Use | Mobile
Web01 | 2.8.150123.1 | Last Updated 13 Jul 2010
Article Copyright 2006 by Cedric Moonen
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid