简单的运用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);	
}




你可能感兴趣的:(简单的运用CChartCtrl)