簡單的運用CChartCtrl

我想做個這個效果圖

1:添加一個定製控件到對話框資源,然後查看屬性並修改屬性如圖:


2:在對話框類添加一個變量m_chartCtrl ;當然要加上#include "ChartCtrl.h" 

3:在 DoDataExchange函數添加一個DDX_Control

    

void CChartDemoDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CChartDemoDlg)
    // Add this line with the appropriate ID and variable name
    DDX_Control(pDX, IDC_CHARTCTRL, m_ChartCtrl);
    //}}AFX_DATA_MAP
}
void CMyClass::InitChartCtrl()
{
	m_chartCtrl.SetBackColor(RGB(0, 255, 0));
	m_chartCtrl.RefreshCtrl();

	TChartString strTitle = _T("工資分析圖");    //圖表標題
	CChartTitle *pTitle = m_chartCtrl.GetTitle();
	pTitle->AddString(strTitle);

	CChartAxis* pLeftAxis = m_chartCtrl.GetLeftAxis();	
	pLeftAxis->SetMinMax(5, 20000);
	pLeftAxis->GetLabel()->SetText(_T("RMB"));  //左軸label

	CChartAxis* pBottomAxis = m_chartCtrl.GetBottomAxis();	
	pBottomAxis->SetMinMax(0, 12);
	pBottomAxis->GetLabel()->SetText(_T("月份")); //右軸label

	CChartLineSerie *pSeries = m_chartCtrl.AddSerie(CChartSerie::stLineSerie)->GetAsLine();  //獲得line指針

	double XValues[13], YValues[13];    //根據x, y軸的數據畫線
	for (int i = 0;i <= 12;i++)	 
	{
		XValues[i] = i;		
	}	
	
	memset(YValues, 0, 13*sizeof(double));
	YValues[0] = 0;
	YValues[1] = 5100;
	YValues[2] = 11300;

	ASSERT(pSeries != NULL);
	
	pSeries->SetPoints(XValues,YValues,13);
	pSeries->SetColor(RGB(255,0,0));
	pSeries->SetWidth(5);	
}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章