ChartCtrl学习------柱状图绘制

261 篇文章 10 订阅

开发中有时候会用到柱状图显示,主要用到的类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);
}

柱状图的效果如下所示:

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值