ChartCtrl学习------折线图绘制

折线图由多个点连接而成,核心代码如下:

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);
}

效果图:


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部