资源简介
1.编译器VS2015,C++自绘漂亮柱状图
2.可用于数据汇总.
3.亲测可用

代码片段和文件信息
#include “stdafx.h“
#include “MyGraphs.h“
CMyGraphs::CMyGraphs()
{
}
CMyGraphs::~CMyGraphs()
{
}
BEGIN_MESSAGE_MAP(CMyGraphs CStatic)
ON_WM_ERASEBKGND()
ON_WM_PAINT()
END_MESSAGE_MAP()
BOOL CMyGraphs::OnEraseBkgnd(CDC* pDC)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
return true;
//return CStatic::OnEraseBkgnd(pDC);
}
void CMyGraphs::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CStatic::OnPaint()
Graphics graphics(dc);
graphics.SetSmoothingMode(SmoothingModeAntiAlias);//消除锯齿
graphics.SetSmoothingMode(SmoothingModeHighQuality);//高质量
CRect m_rect;
GetClientRect(&m_rect);
m_rect.InflateRect(0 0 -2 -2);
Pen pen_bright(Color(255 250 250) 2);
Pen pen_gloomy(Color(210 210 210) 2);
Pen pen_grid(Color::SkyBlue 1);
Point pt_gloomy[3] = { Point(m_rect.rightm_rect.top)
Point(m_rect.leftm_rect.top)
Point(m_rect.leftm_rect.bottom)};
graphics.DrawLines(&pen_gloomy pt_gloomy 3);
Point pt_bright[3] = { Point(m_rect.rightm_rect.top)
Point(m_rect.rightm_rect.bottom)
Point(m_rect.leftm_rect.bottom) };
graphics.DrawLines(&pen_bright pt_bright 3);
for (int i = 1; i < 5; i++)
{
Point pt[2];
pt[0] = { m_rect.leftm_rect.top + m_rect.Height() *i/ 5 };
pt[1] = { m_rect.rightm_rect.top + m_rect.Height() *i/ 5 };
graphics.DrawLine(&pen_grid pt[0] pt[1]);//横线
pt[0] = { m_rect.left + m_rect.Width() *i/ 5 m_rect.top };
pt[1] = { m_rect.left + m_rect.Width() *i/ 5 m_rect.bottom };
graphics.DrawLine(&pen_grid pt[0] pt[1]);//竖线
}
//画柱状图
GraphicsPath graphPath[2];
SolidBrush brush_gra(Color::YellowGreen);
Rect rt[4]rct[4];
for (int j = 1; j < 5; j++)
{
rt[j - 1] = { m_rect.left + m_rect.Width() *j / 5 -12//第一组
m_rect.bottom-m_rect.Height()*j/10
12
m_rect.Height()*j / 10 };
rct[j - 1] = { m_rect.left + m_rect.Width() *j / 5 //第二组
m_rect.bottom - m_rect.Height()*j / 5
12
m_rect.Height()*j / 5 };
}
graphPath[0].AddRectangles(rt4);
graphics.FillPath(&brush_gra &graphPath[0]);
graphPath[1].AddRectangles(rct 4);
graphics.FillPath(&SolidBrush(Color::RoyalBlue) &graphPath[1]);
Point pt_line[6] = { Point(m_rect.leftm_rect.bottom)
Point(m_rect.left + m_rect.Width() * 1 / 5 m_rect.Height() * 4 / 5)
Point(m_rect.left + m_rect.Width() * 2 / 5 m_rect.Height() * 1 / 5)
Point(m_rect.left + m_rect.Width() * 3 / 5 m_rect.Height() * 3 / 5)
Point(m_rect.left + m_rect.Width() * 4 / 5 m_rect.Height() * 2 / 5)
Point(m_rect.left + m_rect.Width() * 5 / 5 m_rect.Height() * 3 / 5) };
graphics.DrawCurve(&Pen(Color::Red2) pt_line 6);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2956 2019-04-17 15:50 柱状图\MyGraphs.cpp
文件 209 2019-04-17 11:32 柱状图\MyGraphs.h
目录 0 2019-05-17 09:48 柱状图
----------- --------- ---------- ----- ----
3165 3
相关资源
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
- c++ 画图(14Qt-XPS)
- c++多边形交并差运算
评论
共有 条评论