MFC 直方图

来源:互联网 发布:电子狗通用升级数据 编辑:程序博客网 时间:2024/06/06 13:18
void COFunView::OnDraw(CDC* pDC)
{
COFunDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
const int x0 = 20,y0=10,x1 = 500,y1=370; //定义视口的顶点在窗口中的坐标
const int N = 12,dx = (x1-x0)/N;//数据的个数及条图的宽度
int a[N] = {172,33,81,266,158,338,237,67,205,76,116,219};


CBrush br;
int i,x;


srand((unsigned)time(NULL));
pDC->Rectangle(CRect(x0,y0,x1,y1));


for (i = 0,x=x0;i<N;++i,x+=dx)
{
br.CreateHatchBrush(rand()%6,RGB(rand()%200,rand()%200,rand()%200));


pDC->SelectObject(&br);
pDC->Rectangle(x,y1-a[i],x+dx,y1);
pDC->SelectStockObject(WHITE_BRUSH);
br.DeleteObject();
}
}
原创粉丝点击