折线图由多个点连接而成,核心代码如下:
void _InitZXSample()
{
// Disable the refresh
m_chartCtrl.EnableRefresh(false);
// Create the bottom axis and configure it properly
CChartStandardAxis* pBottomAxis =
m_chartCtrl.CreateStandardAxis(CChartCtrl::BottomAxis);
pBottomAxis->SetMinMax(0, 10);
// Create the left axis and configure it properly
CChartStandardAxis* pLeftAxis =
m_chartCtrl.CreateStandardAxis(CChartCtrl::LeftAxis);
pLeftAxis->SetMinMax(0, 100);
pLeftAxis->GetLabel()->SetText(_T("左侧"));
// Create the right axis and configure it properly
CChartStandardAxis* pRightAxis =
m_chartCtrl.CreateStandardAxis(CChartCtrl::RightAxis);
pRightAxis->SetVisible(true);
pRightAxis->GetLabel()->SetText(_T("右侧"));
pRightAxis->SetMinMax(0, 100);
// 设置标题
m_chartCtrl.GetTitle()->AddString(_T("标题"));
CChartFont titleFont;
titleFont.SetFont(_T("Arial Black"), 120, true, false, true);
m_chartCtrl.GetTitle()->SetFont(titleFont);
m_chartCtrl.GetTitle()->SetColor(RGB(0, 0, 128));
//设置整个背景颜色
m_chartCtrl.SetBackGradient(RGB(255, 255, 255), RGB(150, 150, 255), gtVertical);
//x轴 y轴的坐标对应图像中的点
double x[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, y[10] = { 10, 30, 40, 50, 40, 60, 90, 80, 70, 50 };
CChartLineSerie *pLineSerie1 = nullptr;
m_chartCtrl.RemoveAllSeries();
pLineSerie1 = m_chartCtrl.CreateLineSerie();
pLineSerie1->SetSeriesOrdering(poNoOrdering);//设置为无序
pLineSerie1->AddPoints(x, y, 10);
pLineSerie1->SetName(_T("第一条折线图"));
// Re enable the refresh
m_chartCtrl.EnableRefresh(true);
}
效果图: