www.pudn.com > RMS2000_C.rar > Chart.h


/////////////////////////////////////////////////////////// 
// Originator : Kris Jearakul  tuktun@hotmail.com 
//				http://krisj.iwarp.com 
// Comment	: Use with your own risk !! 
 
 
#ifndef _CHART_DOT_H 
#define _CHART_DOT_H 
 
#if _MSC_VER > 1000 
#pragma once 
#endif // _MSC_VER > 1000 
 
 
#ifndef MAX 
#define MAX 1 
#endif 
 
#ifndef MIN 
#define MIN 0 
#endif 
 
#define MAX_SERIES 60 
 
class CPlotSerie  
{ 
 
public : 
	CPlotSerie() ; 
	BOOL bIsPlotAvailable ; 
	double *dValueX ; 
	double *dValueY ; 
	COLORREF m_plotColor ; 
	BOOL AllocSerie(UINT nPoint); 
	BOOL FreeSerie(); 
 
protected: 
	BOOL bBufferAllocated; 
} ; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Chart.h : header file 
// 
 
///////////////////////////////////////////////////////////////////////////// 
// CChart window 
class CChart : public CWnd 
{ 
 
public: 
	CChart(); 
	CBitmap m_BkBitmap; 
	BOOL Create(DWORD dwStyle, CRect &rect, CWnd *pParent, UINT id); 
	void SetChartLabel(CString strX,CString strY); 
	void PrintChart(CDC *pDC, int x, int y); 
	void ClearChart(); 
	void SetGridXYNumber(int gridx, int gridy); 
	void SetChartTitle(CString str); 
	//void MoveWindow(CRect &Rect); 
	BOOL AllocSerie(int nSerie); 
	BOOL SetXYValue(double x, double y, int index, int iSerieIdx ); 
	void SetAxisStyle(int iStyle); 
	BOOL SetRange( double dMinX, double dMaxX, double dMinY, double dMaxY); 
	CPoint Corrdinate(double x, double y); 
	virtual void Invalidate(BOOL bErase = FALSE); 
	virtual ~CChart(); 
 
	CPlotSerie mpSerie[MAX_SERIES] ; 
	BOOL bLogScale ; 
	int nSerieCount ; 
	CRect  m_ctlRect ; 
	CRect  m_clientRect ; 
	COLORREF m_BGColor ; 
	COLORREF m_AxisColor ; 
	COLORREF m_GridColor ; 
	COLORREF m_TextTitleColor ; 
	COLORREF m_TextLabelColor ; 
 
	// Generated message map functions 
protected: 
	BOOL bFontIsCreate ; 
	CBitmap *m_pOldBkBitmap; 
	CDC memBkDC; 
	void DrawBackGround(CDC *pDC); 
	BOOL bBkNeedToUpdate; 
	void SetChartTitle(CDC *pDC); 
	virtual void Plot(CDC *pDC); 
	virtual void DrawBorder(CDC *pDC); 
	virtual void DrawChartTitle(CDC *pDC); 
	virtual void DrawGrid(CDC *pDC); 
	virtual void DrawAxis(CDC *pDC); 
	virtual void DrawGridLabel(CDC *pDC); 
	virtual void CreateFont(); 
	void DrawLogGrid(CDC *pDC); 
	void ResCalc(); 
	void CalcRect(); 
 
	CString strLabelX, strLabelY ; 
	CString strChartTitle ; 
	CFont *pLegendFontY ; 
	CFont *pLegendFontX ; 
	CFont *pTitleFont; 
	CRect m_axisRect; 
	int iChartType ; 
	int nPointCount ; 
	int nPlotIndex ; 
	int nGridY, nGridX ; 
	double dResY, dResX ; 
	double dRangeY[2], dRangeX[2]; 
	 
	BOOL bIsSerieAllocated ; 
 
 
 
 
 
	//{{AFX_MSG(CChart) 
	afx_msg void OnPaint(); 
	//}}AFX_MSG 
	DECLARE_MESSAGE_MAP() 
}; 
 
 
 
///////////////////////////////////////////////////////////////////////////// 
 
//{{AFX_INSERT_LOCATION}} 
// Microsoft Visual C++ will insert additional declarations immediately before the previous line. 
 
#endif  
 
/*ʹÓ÷½·¨  
	//Allocate space for series . 
	if ( !m_Chart2d.AllocSerie(100) ) { 
		AfxMessageBox("Error allocating chart serie") ; 
        return -1; 
	} 
	// Customize chart  
	m_Chart2d.SetChartTitle("2D Chart"); 
	m_Chart2d.SetChartLabel("X","Y"); 
	m_Chart2d.SetGridXYNumber(10,2); 
	m_Chart2d.SetAxisStyle(1); 
	m_Chart2d.SetRange(0,96,0,1000); 
	m_Chart2d.SetAxisStyle(0); 
	m_Chart2d.mpSerie[0].m_plotColor = RGB(0,125,255); 
	m_Chart2d.mpSerie[1].m_plotColor = RGB(255,0,0); 
	m_Chart2d.m_BGColor = RGB(255,255,0); 
	m_Chart2d.SetGridXYNumber(10,10); 
	//m_Chart2d.bLogScale = TRUE ; 
	// Create chart . 
	m_Chart2d.Create(WS_CHILD|WS_VISIBLE,CRect(10,10,300,200),this,1000); 
 
 
 
		for ( int i = 0 ; i < 100 ; i++) 
		{ 
			float value =rand()%500+100; 
			m_Chart2d.SetXYValue((double)i,fabs(value),i,0); 
			value =rand()%400; 
			m_Chart2d.SetXYValue((double)i,fabs(value),i,1); 
  
		} 
		m_Chart2d.Invalidate(); 
 
*/