开发中有时候会用到柱状图显示,主要用到的类CChartBarSerie,简单的示例如下:
void _InitBar()
{
m_chartCtrl.EnableRefresh(false);
CChartStandardAxis* pBottomAxis =
m_chartCtrl.CreateStandardAxis(CChartCtrl::BottomAxis);
pBottomAxis->SetMinMax(0, 20);
pBottomAxis->SetDiscrete(true);
CChartStandardAxis* pLeftAxis =
m_chartCtrl.CreateStandardAxis(CChartCtrl::LeftAxis);
pLeftAxis->SetMinMax(0, 100);
pLeftAxis->GetLabel()->SetText(_T("左轴"));
CChartStandardAxis* pRightAxis =
m_chartCtrl.CreateStandardAxis(CChartCtrl::RightAxis);
pRightAxis->SetVisible(true);
pRightAxis->GetLabel()->SetText(_T("右轴"));
pRightAxis->SetMinMax(0, 200);
m_chartCtrl.GetLegend()->SetVisible(true);
m_chartCtrl.GetLegend()->SetHorizontalMode(true);
m_chartCtrl.GetLegend()->UndockLegend(80, 50);
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);
CChartBarSerie* pBarSeries = m_chartCtrl.CreateBarSerie();
pBarSeries->AddPoint(1, 10);
pBarSeries->SetColor(RGB(255, 0, 0));
pBarSeries->SetName(_T("柱状图解释"));
// Re enable the refresh
m_chartCtrl.EnableRefresh(true);
}
柱状图的效果如下所示: