CBarChart柱形图类
在用VC做有关图表的时候,感觉不是那么方便,在codeproject找到一个柱形图的实用类,原文地址为:http://www.codeproject.com/KB/miscctrl/CBarChart.aspx。它可以很快速的生成柱状图,并且支持输出位图、支持打印、支持从数据库导入。
下面介绍下基本步骤:
1.添加BarChart.cpp 和 BarChart.h工程;
2.在需要使用的地方添加头文件
#include "BarChart.h"
3.定义一个CBarChart的变量;
CBarChart m_chart;
CBarChart m_chart;
4.在实现文件里面使用Create方法创建图表柱形图;
1).创建图表
// Create a bar chart control
if (!m_chart.Create(
rcBound, // Bounding rectangle of the control
this, // A pointer to the parent window to be shown on
0 )) // ID of this control
{
// Error, can't create the chart
}
//If Create suceeds, it returns TRUE.
2).设置标题、背景颜色
m_chart.SetTitle("A test chart, displaying some dummy data...");
m_chart.SetBKColor(RGB(255, 255, 240));
3).添加柱形图表
m_chart.AddBar(
1600.356, // A value to be shown at the top of the bar
"Jan", // A label under the bar chart
RGB(255,255,0)); // Color of the bar
4).网格线显示、柱形描述、柱形提示
m_chart.ShowGrid(m_bShowGrid, TRUE); // Show/Hide grids
m_chart.ShowBarText(1, m_bShowText, TRUE); // Show/Hide values(top)
m_chart.ShowLabel(m_bShowLabel, TRUE); // Show/Hide labels(bottom)
m_chart.ShowTooltip(m_bShowTip); // Activate/deactivate tooltips
5).网格线大小
SetGridLines(
int nHorLineCount, // Number of horizontal lines, 0 = ignore
int nVerLineCount, // Number of vertical lines, 0 = ignore
BOOL bFixedSize, // If TRUE, first 2 parameters will be ignored
int nFixedSize) // A fixed value that defines distance between 2 lines,
// Will be used if previous parameter is set to TRUE
6).缩放
m_chart.SetAutoScale(m_bScale); // Set chart to be auto scaled
// Reposition window, so it finds out the size to fit into
m_chart.SetWindowPos( 0, 0, 0,
rcClient.Width(),
rcClient.Height() , SWP_NOMOVE);
m_chart.Refresh(); // Force the chart to redraw itself // You might also need to override OnSize of the
// Parent to position the chart, so it is always at the size you like
7).删除柱形
m_chart.RemoveAt(nRemIndex); // Removes the item indexed nRemIndex.
// Index is zero based.
m_chart.RemoveAll(); // Removes all bars
8).保存bmp文件
// Save chart as a bitmap file
if (!m_chart.SaveToFile())
{
AfxMessageBox(m_chart.GetLastErrorMessage());
};
9).打印
m_chart.Print(); // Prints the whole chart fitted in the page.
// If you have a lot of bars, I recommend selecting landscape in the
// print dialog box.
10).连接数据库
//--------------------------------------------创建ODBC连接
// Use this form to call a stored procedure or a query and use
// result set as chart input ReadFromDatabase("DS Name", "Stored proc/Query Name", "List of all parameters",
"Bars Color", "UserName", "Password")); // Note that the query or stored procedure MUST have at least 2 columns,
// First column MUST be of type char with maximum length of 50 and
// Second a double. These columns will be used as input data for the chart. //--------------------------------------------连接数据库表
m_chart.ReadFromDatabase("DS Name", "Table name", "Filter",
"Laabel column name", "dValue column name",
Bars color , "username", "password"); //--------------------------------------------显示
if (!m_chart.ReadFromDatabase("CHTst", "SpChartGetSale", "1, 12",
RGB(0, 0, 0), "hamed", "hamed"))
{
AfxMessageBox(m_chart.GetLastDatabaseErrMessage());
};
or
m_chart.ReadFromDatabase("CHTst", "Sales", "",
"Month", "SaleRate",
RGB(0, 0, 0) , "hamed", "hamed");
5.实例
CRect rcClient;
GetClientRect(&rcClient); if (!m_chart.Create(CRect(110, 50,
rcClient.Width()-10,
rcClient.Height() - 50), this, 1050 ))
{
if (!m_chart.GetSafeHwnd())
{
AfxMessageBox("Unable to create the chart control");
return;
} m_chart.Reset();
m_chart.SetAutoScale(FALSE);
} m_chart.SetTitle("A test chart, displaying some dummy data...");
m_chart.SetBKColor(RGB(255, 255, 240));
m_chart.ShowTooltip(TRUE); m_chart.AddBar(1600.356,"Jan", RGB(255,255,0));
m_chart.AddBar(2841.5468,"Feb", RGB(255,0,0));
m_chart.AddBar(1045.3258,"Mar", RGB(100,100,200));
m_chart.AddBar(1502.215,"Apr", RGB(0,255,0));
m_chart.AddBar(1467,"MAY", RGB(255,255,255));
m_chart.AddBar(1678.354,"JUN", RGB(200,255,255));
m_chart.AddBar(1785.689,"JUL", RGB(255,240,40));
m_chart.AddBar(1283.099,"AUG", RGB(255,60,130));
m_chart.AddBar(1554.879,"SEP", RGB(255,255,200));
m_chart.AddBar(1400.10,"OCT", RGB(130,235,250));
m_chart.AddBar(1600.556,"NOV", RGB(100,150,200));
m_chart.AddBar(1900.3546,"DES", RGB(150,240,80), TRUE);
运行结果:

源文件下载:http://download.csdn.net/detail/wuyuan2011woaini/9592992
CBarChart柱形图类的更多相关文章
- Java类的继承与多态特性-入门笔记
相信对于继承和多态的概念性我就不在怎么解释啦!不管你是.Net还是Java面向对象编程都是比不缺少一堂课~~Net如此Java亦也有同样的思想成分包含其中. 继承,多态,封装是Java面向对象的3大特 ...
- ***百度统计图表Echarts的php实现类,支持柱形图、线形图、饼形图
/** * 百度数据统计图表echart的PHP实现类 * * 原作者: * @author: chenliujin <liujin.chen@qq.com> * @since 2013- ...
- AChartEngine 安卓折线图 柱形图等利器
http://www.eoeandroid.com/thread-548233-1-6.html 最近公司项目中要用到折线图,状态类型的图标要用到折线图,柱形图等,并且能够动态显示,在网上找了许多de ...
- iOS使用Charts框架绘制—柱形图
首先看一下最终要实现的效果: 最终效果 一.初始化barChartView 绘制柱形图需要用到BarChartView这个类,下面是初始化代码: self.barChartView = [[BarCh ...
- XCL-Charts图表库中柱形图的同源风格切换介绍
柱形图是被使用最多的图之中的一个,在写XCL-Charts这个Android图表库时,为它花费的时间相当多,不是由于有多难绘制,而是要在设计时怎样才干保证图基类能适应各种情况,能灵活满足足够多的需求, ...
- Android绘图机制(四)——使用HelloCharts开源框架搭建一系列炫酷图表,柱形图,折线图,饼状图和动画特效,抽丝剥茧带你认识图表之美
Android绘图机制(四)--使用HelloCharts开源框架搭建一系列炫酷图表,柱形图,折线图,饼状图和动画特效,抽丝剥茧带你认识图表之美 这里为什么不继续把自定义View写下去呢,因为最近项目 ...
- 关于echarts.js 柱形图
echarts.js官网: http://www.echartsjs.com/index.html 这是我所见整理最详细echarts.js 柱形图博客: https://blog.csdn.net/ ...
- High-speed Charting Control--MFC绘制图表(折线图、饼图、柱形图)控件
原文地址:https://www.codeproject.com/articles/14075/high-speed-charting-control 本文翻译在CodeProject上的介绍(主要还 ...
- 【207】WinForm Chart类
目录: 在工具箱中找到 Chart 控件并使用 设置 Chart 属性 代码中设置属性 属性中设置属性 Chart 类说明 ChartAreas ChartAreaCollection 类 Chart ...
随机推荐
- Django--models基础
需求 了解models字段和参数 速查 models.py 1 2 3 class UserInfo(models.Model): ctime = models.DateTimeField( ...
- [Tool] 常用开发工具注册码(持续更新)
OS win10 激活 命令行 打开命令提示符( 管理员 ) 输入 slmgr /ipk W269N-WFGWX-YVC9B-4J6C9-T83GX 回车 再输入 slmgr /skms kms.xs ...
- 数论 - 欧拉函数模板题 --- poj 2407 : Relatives
Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11372 Accepted: 5544 Descri ...
- .net中以传引用的方式 向方法中传参数
CLR(CommonLanguageRuntime)公共语言运行时,允许以传引用而非传值的方式传递参数.在C#中,这是用关键字 out 和ref来做到的. 从CLR角度来看,这两个关键字没什么区别,生 ...
- Winform开发框架的业务对象统一调用方式
在这个纷繁的社会里面,统一性的特点能够带来很多高效的产出.牢固的记忆,这种特征无论对于企业.个人的开发工作,知识的传承都有着非常重要的作用,Winfrom框架本身就是基于这个理念而生,从统一的数据库设 ...
- 【原创】有关Silverlight控件DataGrid的绑定数据后单元格单独复制的功能实现分析
前些日子,公司新需求需要对silverlight的datagrid进行局部任意单元格数据可复制,查阅了半天网络资料愣是没找到相关资料,开始还以为是silverlight的bug根部无法实现, 最后还是 ...
- Netty学习之客户端创建
一.客户端开发时序图 图片来源:Netty权威指南(第2版) 二.Netty客户端开发步骤 使用Netty进行客户端开发主要有以下几个步骤: 1.用户线程创建Bootstrap Bootstrap b ...
- AxWebBrowser与WebBrowserU盾登陆时的使用
PS:上个月为财务小妹做了个自动上传报表的工具,财务妹子表示调戏我很开心T_T~~. 由于该小程序涉及到登陆,准备用WebBroswer,这一下撞墙上了,无法展示U盾密码框. 我在博问上的问题 ...
- 与众不同 windows phone (48) - 8.0 其它: C# 调用 C++
[源码下载] 与众不同 windows phone (48) - 8.0 其它: C# 调用 C++ 作者:webabcd 介绍与众不同 windows phone 8.0 之 其它 C# 中调用 W ...
- PHP OAuth2 Server库
想找比较正宗的库,查了蛮久的.最后在 oauth官方站上,看到PHP版本的相关链接. 发现都是php 5.3版本以上的环境,基于命名空间的写法编写的. 访问下面这个页面,难得,发现文档给出了5.2版本 ...