一个画图类,类似ms_chart的线图,适用于科学仿真数据分析(二)
|
51自学网 2015-08-30 http://www.wanshiok.com |
|
续上节.下面是类的实现.为了消除做图时的屏幕的闪烁,所以采用了位图的方式.在做图时充分考虑到了数值分析时的特点,作了三点处理:
(一)将网格线进行了自动调整,确保数据显示位于区域之内 (二)如果出现零值,则确保0值网格线的出现 (三)自动调整数值的显示方式,确保了横轴显示效果 因此,非常适合于数值分析的图形显示,当然,由于采用了位图帖图的方式进行做图,你完全可以用它来进行实时绘图. LyhLineChart.h : header file ******文中的file字样是粘贴的时候产生的,请自己删除********
#if !defined(AFX_LYHLINECHART_H__9269BA72_F2CB_4D4D_9EF8_624E8FA939BD__INCLUDED_) #define AFX_LYHLINECHART_H__9269BA72_F2CB_4D4D_9EF8_624E8FA939BD__INCLUDED_
#if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 // LyhLineChart.h : header file // #include <afxtempl.h> struct DataStru{ double x; double y; }; typedef CList<DataStru,DataStru> CItemData; class CLineChartItem:public CObject { public:
CLineChartItem() { legendcolor=RGB(0,0,128); iWidth=1; iStyle=PS_SOLID; }; virtual ~CLineChartItem() { if(m_data.GetCount()>0) m_data.RemoveAll(); }; CItemData m_data;//坐标数据 COLORREF m_colorLine;//线色 CString m_legend;//线的说明,图例中显示的文字内容 COLORREF legendcolor; int iWidth,iStyle;//线宽,线型 };
typedef CTypedPtrArray <CObArray, CLineChartItem*> CItemArray;
class CLyhLineChartSet:public CObject { public: UINT RIGHTSPACE; file://表格右侧的空间 UINT CHARSPACE; file://坐标值和表格线之间的空间 UINT VLineNum;//Y轴方向的网格线数 UINT HLineNum;//X轴方向的网格线数 BOOL bBorder;//是否显示外部边框 UINT BorderWidth; BOOL bxInBorder;//是否显示坐标线内部方格线, BOOL byInBorder;//是否显示坐标线内部方格线, COLORREF BorderColor;//边框颜色 COLORREF InBorderColor;//坐标线颜色 COLORREF bkColor;//背景色 CString XTitle;// X标题内容 CString YTitle;// Y标题内容 CString Title;// 标题内容 CString FootNote;//脚注内容 COLORREF XTileColor;//X标题颜色 COLORREF YTileColor;//Y标题颜色 COLORREF TileColor;//标题颜色 COLORREF FootColor;//脚注颜色 COLORREF axiednumcolor; BOOL bLegend;//是否显示图例,图例内容存储在绘图数据结构内 BOOL autorange;//选择自动范围,则每次添加数据就自动计算更新范围值 double xMax,yMax,xMin,yMin;//坐标轴范围值 int fontsize; CString fontname; BOOL bStretch; CLyhLineChartSet() {//缺省设置 RIGHTSPACE=5; CHARSPACE=2; VLineNum=10; HLineNum=10; BorderWidth=1; bBorder=true; bxInBorder=true; byInBorder=true; BorderColor=RGB(0,0,0); InBorderColor=RGB(0,0,0); XTileColor=RGB(0,0,128); YTileColor=RGB(0,0,128); TileColor=RGB(0,0,255); FootColor=RGB(0,0,0); bLegend=false; xMax=100.0; yMax=100.0; xMin=0.0; yMin=0.0; autorange=true; bkColor=RGB(150,150,150); XTitle="X Title"; YTitle="Y Title"; Title="标 题"; FootNote="FOOT Text"; fontsize=16; fontname="KaiTi"; axiednumcolor=RGB(0,0,0); bStretch=false; }
}; ///////////////////////////////////////////////////////////////////////////// // CLyhLineChart window #define NODATA 1.7E300//标识该点数据无数据 #define DEFAULTCOLOR RGB(150,150,150) class CLyhLineChart : public CWnd { // Construction public: CLyhLineChart();
// Attributes public: CItemArray m_items; // Operations public:
// Overrides // ClassWizard generated virtual function overrides file://{{AFX_VIRTUAL(CLyhLineChart) file://}}AFX_VIRTUAL
// Implementation public: void SetAxiedColor(COLORREF crColor); void SetPicFont(int fontsize,CString fontname); COLORREF SetBkColor(COLORREF crColor); void ShowYGrid(BOOL bSign=TRUE);//Display y axied grid line void ShowXGrid(BOOL bSign=TRUE);//Display x axied grid line int SetYDivision(int nDiv);//set Y axied max division int SetXDivision(int nDiv); int GetLineNum();//get the total num of line in chart int GetIndex(CString csLegend);//返回图例名对应的索引,-1表示该图例不存在 void DeleteLine(int nIndex=1);//删除nIndex对应的图项,索引会改变 void SetLegend(CString csLegend,int nIndex=1,COLORREF crColor=DEFAULTCOLOR); BOOL ShowLegeng(BOOL bShow=TRUE); CString SetFootNote(CString csFootNote, COLORREF crColor=DEFAULTCOLOR); CString SetXTitle(CString csXTitle,COLORREF crColor=DEFAULTCOLOR); CString SetYTitle(CString csYTitle,COLORREF crColor=DEFAULTCOLOR); COLORREF GetTitle(CString &csTitle); void SetTitle(CString csTitle=(LPCTSTR)NULL,COLORREF crColor=DEFAULTCOLOR);//设置标题,为NULL时不显示 void SetLineStyle(int nStyle, int nWidth, COLORREF crColor ,int nIndex=1); int AddSplitData(int nIndex=1);//设置间断,非连续作图时调用 int BatchAddData(double *x,double *y,int nCount,int nIndex=1); int AddData(double x,double y,int LineIndex=1);//LineIndex为线数 int CalDecNum(double minnum,double maxnum,CString &data);//返回值为小数点位数, file://字符串存储了形成后的最大值的整数的字符串 void Refresh(); BOOL SetAutoRange(BOOL bAuto=TRUE,double minx=0.0,double maxx=100.0,double miny=0.0,double maxy=100.0);//设置范围 BOOL AddLineToChart(COLORREF color=DEFAULTCOLOR); BOOL RegisterWndClass(HINSTANCE hInstance); virtual ~CLyhLineChart();
// Generated message map functions protected: void DrawPic(); CDC m_MemDC; CBitmap m_Bitmap; file://{{AFX_MSG(CLyhLineChart) afx_msg void OnPaint(); afx_msg void OnSize(UINT nType, int cx, int cy); file://}}AFX_MSG DECLARE_MESSAGE_MAP() private: void CalRange(); CLyhLineChartSet m_set; };
/////////////////////////////////////////////////////////////////////////////
file://{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_LYHLINECHART_H__9269BA72_F2CB_4D4D_9EF8_624E8FA939BD__INCLUDED_)
全文完.  
说明:本教程来源互联网或网友上传或出版商,仅为学习研究或媒体推广,wanshiok.com不保证资料的完整性。
|
|