DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

源博客:http://www.codeproject.com/Articles/9350/2D-Animated-Charts

源代码:http://download.csdn.net/detail/nuptboyzhb/4202051

简介:CGraphObject是由CWnd类派生出来,因此,CGraphObject类是一个窗口类;即,每个图表都是一个窗口;因此,每一个图表的创建,应该放在OnCreate函数或OnInitialUpdate函数中;其应用过程,与窗口类型的控件(如CButton)非常类似;

应用:

1.       将相关的.h.cpp文件复制到工程目录中,并载入到工程;

[GraphObject.h GraphObject.cpp]

[MathParams.h]

[2DLineGraph.h 2DLineGraph.cpp]

[2DBarGraph.h 2DBarGraph.cpp]

[2DPieGraph.h 2DPieGraph.cpp]

2.       在类所在的头文件中,包含其相应的头文件;#include "GraphObject.h"并定义相应的资源ID窗口;

3.       为类增加图表类型的指针作为其成员变量;

CGraphObject* m_pGraphObject1;

//……一下详见代码

4.       View类的OnInitialUpdate()函数中,初始化这些图表窗口,或对话框的OnInitDialog()函数;或Oncreate函数;(注意:视图窗口完全建立后第一个被框架调用的函数。框架在第一次调用OnDraw前会调用OnInitialUpdate

 

// Create CGraphObject1 ( 2DPie graph )

m_pGraphObject1 = new CGraphObject();

//创建一个图表窗口,大小,父窗口的指针,资源ID(自定义)

m_pGraphObject1->Create( NULL, NULL, NULL, CRect(40,20,240,220), this, ID_OBJECT_GRAPH_1, NULL );

//注意,应在头文件中定义资源ID,如:#define ID_OBJECT_GRAPH_1 12345

// Create graph and set graph parameters

m_pGraphObject1->CreateGraph( GT_2DPIE );//创建一个二维饼状图

m_pGraphObject1->SetGraphBackgroundColor( RGB(255,255,255) );//设置背景颜色

m_pGraphObject1->SetGraphTitle( "2DPie No. 1" );//设置标题

m_pGraphObject1->SetGraphSubtitle( "animation - none" );//设置子标题

m_pGraphObject1->SetGraphTitleShadow( FALSE );//标题无阴影

m_pGraphObject1->SetGraphSubtitleShadow( FALSE );//子标题无阴影

m_pGraphObject1->SetGraphTitleColor( RGB(128,128,128) );//设置标题颜色

m_pGraphObject1->SetGraphSubtitleColor( RGB(96,96,96) );//设置子标题颜色

//设置注释的背景颜色

m_pGraphObject1->SetGraphLegendBackgroundColor( RGB(208,208,208) );

// Add graph segments

//为饼形图添加数据段(百分比,颜色,名程)

m_pGraphObject1->Add2DPieGraphSegment( 40, RGB(255,0,0), "Seg_1" );

m_pGraphObject1->Add2DPieGraphSegment( 25, RGB(0,255,0), "Seg_2" );

m_pGraphObject1->Add2DPieGraphSegment( 15, RGB(0,0,255), "Seg_3" );

m_pGraphObject1->Add2DPieGraphSegment( 5, RGB(255,0,255), "Seg_4" );

m_pGraphObject1->Add2DPieGraphSegment( 8, RGB(0,255,255), "Seg_5" );

m_pGraphObject1->Add2DPieGraphSegment( 7, RGB(255,255,0), "Seg_6" );

// 设置图像动画

m_pGraphObject1->SetGraphAnimation( FALSE, AT_PIE_DRAW );

5.       View类的析构函数中,删除成员变量的指针;

m_pGraphObject1->DestroyWindow();//关闭窗口

delete m_pGraphObject1;//删除指针

注意:本人将MathParams.h进行了修改,新增了

#pragma comment(lib,"Gdi32.lib")

#pragma comment(lib,"Msimg32.lib")

并将MathParams.h被三个图形的.cpp文件中包含

将其封装到Dll动态链接库中

源代码:http://download.csdn.net/detail/nuptboyzhb/4205148

封装后,只需要将[2DGraph.lib][ 2DGraph.dll][ GraphObject.h]这三个文件拷贝到工程目录中即可,在需要用到的地方只需要包含其头文件即可;

#include "GraphObject.h"

#pragma comment(lib,"2DGraph.lib")

然后,下面的编程和上述3-5步骤中相同;

posted on 2013-12-26 15:14  DoubleLi  阅读(1101)  评论(0编辑  收藏  举报