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
A flexible charting control to display 2D data
Prize winner in Competition "MFC/C++ Apr 2006"
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
chartctrl_src.zip
chartctr_demo.zip
res
ChartDemo.ico
// SeriesPropDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ChartDemo.h"
#include "SeriesPropDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSeriesPropDlg dialog


CSeriesPropDlg::CSeriesPropDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSeriesPropDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSeriesPropDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_iHorizAxis = m_iVertAxis = 0;
	m_iSeriesType = 0;
	m_SeriesColour = 0;
	m_iDataType = 0;
	m_fMaxXValue = m_fMinXValue = 0.0;
	m_iPointsNumber = 0;

	m_iRandMinVal = m_iRandMaxVal = 0;
	m_fSineAmplitude = m_fSinePeriod = 0;
	m_fLineSlope = m_fLineOffset = 0;
}


void CSeriesPropDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSeriesPropDlg)
	DDX_Control(pDX, IDC_VERTICALAXIS_COMBO, m_VertAxisCombo);
	DDX_Control(pDX, IDC_HORIZONTALAXIS_COMBO, m_HorizAxisCombo);
	DDX_Control(pDX, IDC_SERIESCOLOUR_BTN, m_ColourSelect);
	DDX_Control(pDX, IDC_SERIESTYPE_COMBO, m_SeriesTypeCombo);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSeriesPropDlg, CDialog)
	//{{AFX_MSG_MAP(CSeriesPropDlg)
	ON_BN_CLICKED(IDC_LINEDATA_RADIO, OnSelectLineData)
	ON_BN_CLICKED(IDC_RANDOMDATA_RADIO, OnSelectRandomData)
	ON_BN_CLICKED(IDC_SINEDATA_RADIO, OnSelectSineData)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSeriesPropDlg message handlers

void CSeriesPropDlg::OnOK() 
{
	TCHAR szName[255];
	GetDlgItem(IDC_SERIESNAME_EDIT)->GetWindowText(szName,254);
	m_strSeriesName = szName;

	if (_tcscmp(szName,_T("")) == 0)
	{
		MessageBox(_T("You must supply a name"),_T("Error"));
		return;
	}

	m_iSeriesType = m_SeriesTypeCombo.GetCurSel();
	m_SeriesColour = m_ColourSelect.GetColour();
	
	TCHAR szBuff[255];
	GetDlgItem(IDC_MAXXVALUE_EDIT)->GetWindowText(szBuff,254); 
//	m_fMaxXValue = (float)_tstof(szBuff);
	m_fMaxXValue = (float)_tcstod(szBuff, NULL);
	GetDlgItem(IDC_MINXVALUE_EDIT)->GetWindowText(szBuff,254); 
//	m_fMinXValue = (float)_tstof(szBuff);
	m_fMinXValue = (float)_tcstod(szBuff, NULL);
	if (m_fMinXValue > m_fMaxXValue)
	{
		MessageBox(_T("Max X value should be > Min X value"));
		return;
	}

	m_iHorizAxis = m_HorizAxisCombo.GetCurSel();
	m_iVertAxis = m_VertAxisCombo.GetCurSel();

	GetDlgItem(IDC_POINTSNUMBER_EDIT)->GetWindowText(szBuff,254); 
#ifdef UNICODE 
	m_iPointsNumber = _wtoi(szBuff);
#else
	m_iPointsNumber = atoi(szBuff);
#endif
	if (m_iPointsNumber < 2)
	{
		MessageBox(_T("Number of points should be > 2"));
		return;
	}

	if ( ((CButton*)GetDlgItem(IDC_LINEDATA_RADIO))->GetCheck() == 1)
	{
		m_iDataType = 0;
	
		GetDlgItem(IDC_DATAPARAM1_EDIT)->GetWindowText(szBuff,254); 
//		m_fLineSlope = (float)_tstof(szBuff);
		m_fLineSlope = (float)_tcstod(szBuff, NULL);
		GetDlgItem(IDC_DATAPARAM2_EDIT)->GetWindowText(szBuff,254); 
//		m_fLineOffset = (float)_tstof(szBuff);
		m_fLineOffset = (float)_tcstod(szBuff, NULL);
	}
	else if ( ((CButton*)GetDlgItem(IDC_SINEDATA_RADIO))->GetCheck() == 1)
	{
		m_iDataType = 1;
	
		GetDlgItem(IDC_DATAPARAM1_EDIT)->GetWindowText(szBuff,254); 
//		m_fSineAmplitude = (float)_tstof(szBuff);
		m_fSineAmplitude = (float)_tcstod(szBuff, NULL);
		GetDlgItem(IDC_DATAPARAM2_EDIT)->GetWindowText(szBuff,254); 
//		m_fSinePeriod = (float)_tstof(szBuff);
		m_fSinePeriod = (float)_tcstod(szBuff, NULL);
		if (m_fSinePeriod == 0)
		{
			MessageBox(_T("Sine period cannot be 0"),_T("Error"));
			return;
		}
	}
	else
	{
		m_iDataType = 2;
	
#ifdef UNICODE 
	GetDlgItem(IDC_DATAPARAM1_EDIT)->GetWindowText(szBuff,254); 
	m_iRandMinVal = _wtoi(szBuff);
	GetDlgItem(IDC_DATAPARAM2_EDIT)->GetWindowText(szBuff,254); 
	m_iRandMaxVal = _wtoi(szBuff);
#else
	GetDlgItem(IDC_DATAPARAM1_EDIT)->GetWindowText(szBuff,254); 
	m_iRandMinVal = atoi(szBuff);
	GetDlgItem(IDC_DATAPARAM2_EDIT)->GetWindowText(szBuff,254); 
	m_iRandMaxVal = atoi(szBuff);
#endif

		if (m_iRandMaxVal < m_iRandMinVal)
		{
			MessageBox(_T("Max random value should be > Min random value"));
			return;
		}
	}

	CDialog::OnOK();
}

BOOL CSeriesPropDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_SeriesTypeCombo.SetCurSel(0);
	m_HorizAxisCombo.SetCurSel(0);
	m_VertAxisCombo.SetCurSel(0);
	((CButton*)GetDlgItem(IDC_LINEDATA_RADIO))->SetCheck(1);

	GetDlgItem(IDC_MINXVALUE_EDIT)->SetWindowText(_T("0.0")); 
	GetDlgItem(IDC_MAXXVALUE_EDIT)->SetWindowText(_T("100.0")); 

	GetDlgItem(IDC_DATAPARAM1_EDIT)->SetWindowText(_T("1.0"));
	GetDlgItem(IDC_DATAPARAM2_EDIT)->SetWindowText(_T("0.0"));
	GetDlgItem(IDC_POINTSNUMBER_EDIT)->SetWindowText(_T("100")); 

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSeriesPropDlg::OnSelectLineData() 
{
	GetDlgItem(IDC_DATAPARAM1_TEXT)->SetWindowText(_T("Line Slope:"));
	GetDlgItem(IDC_DATAPARAM2_TEXT)->SetWindowText(_T("Line Offset:"));
	GetDlgItem(IDC_DATAPARAM1_EDIT)->SetWindowText(_T("1.0"));
	GetDlgItem(IDC_DATAPARAM2_EDIT)->SetWindowText(_T("0.0"));
}

void CSeriesPropDlg::OnSelectRandomData() 
{
	
	GetDlgItem(IDC_DATAPARAM1_TEXT)->SetWindowText(_T("Min Y value:"));
	GetDlgItem(IDC_DATAPARAM2_TEXT)->SetWindowText(_T("Max Y value:"));
	GetDlgItem(IDC_DATAPARAM1_EDIT)->SetWindowText(_T("0"));
	GetDlgItem(IDC_DATAPARAM2_EDIT)->SetWindowText(_T("100"));
}

void CSeriesPropDlg::OnSelectSineData() 
{
	GetDlgItem(IDC_DATAPARAM1_TEXT)->SetWindowText(_T("Sine Amplitude:"));
	GetDlgItem(IDC_DATAPARAM2_TEXT)->SetWindowText(_T("Sine Period:"));
	GetDlgItem(IDC_DATAPARAM1_EDIT)->SetWindowText(_T("100.0"));
	GetDlgItem(IDC_DATAPARAM2_EDIT)->SetWindowText(_T("10.0"));
}

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)

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
Web04 | 2.8.140721.1 | Last Updated 13 Jul 2010
Article Copyright 2006 by Cedric Moonen
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid