QQ登录

只需一步,快速开始

MFC扩展编程实例3D叠加面积图表创建显示

[ 复制链接 ]
MFC扩展编程实例3D叠加面积图表创建显示

当前例程实现三维的叠加面积图表与带百分比叠加面积图表创建显示。
效果如下图。

MFC扩展编程实例3D叠加面积图表创建显示

MFC扩展编程实例3D叠加面积图表创建显示

初始显示的是一般的三维面积图表,点击图表类型按钮可以三个类型图表来回切换。
一般的,叠加的,带百分比叠加的三种类型图表。
点击标签设置可以设置图表标签的显示角度。
点击旋转控件,可以旋转三维图表。

下面是例程实现过程。
创建基于扩展库的单文档工程class CMy123View : public CBCGPFormView。
在默认对话框资源添加两图片控件,ID修改为IDC_ROTATE,IDC_CHART,用于旋转与显示图表。

在视窗类添加自定义变量与函数,函数用于旋转图表。
  1. CBCGPRotationCtrl        m_wndRotate;
  2.         CBCGPChartCtrl      m_wndChart;
  3.         void RotateChart(CBCGPRotationObject::RotationElement hit, double xDelta=10., double yDelta=10., double persperctiveDelta=0.1);
  4.       
复制代码

在视窗类添加虚函数Create,用于初始化图表等变量。

  1. inline double Rand (double dblStart, double dblFinish)
  2. {
  3.         double minVal = min(dblStart, dblFinish);
  4.         double maxVal = max(dblStart, dblFinish);
  5.         return (maxVal - minVal) * (double)rand() / (RAND_MAX + 1) + minVal;
  6. }
  7. BOOL CMy123View::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
  8. {
  9.         BOOL bRst = CBCGPFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);;
  10.         //旋转图表控件初始化;
  11.         m_wndRotate.SubclassDlgItem(IDC_ROTATE,this);
  12.         m_wndRotate.GetRotationObject()->SetAutorepeatMode(100);
  13.         m_wndRotate.GetRotationObject()->SetColorTheme(CBCGPRotationObject::BCGP_COLOR_THEME_VISUAL_MANAGER);
  14.         m_wndRotate.GetRotationObject()->EnablePart(CBCGPRotationObject::BCGP_ROTATION_CLOCKWISE, FALSE);
  15.         m_wndRotate.GetRotationObject()->EnablePart(CBCGPRotationObject::BCGP_ROTATION_COUNTER_CLOCKWISE, FALSE);
  16.         m_wndRotate.GetRotationObject()->EnableFlatIcons();
  17.         //图表初始化;
  18.         m_wndChart.SubclassDlgItem(IDC_CHART,this);       
  19.         CBCGPInfoTipOptions infoTipOptions;
  20.         infoTipOptions.m_StemLocation = CBCGPPopupWindow::BCGPPopupWindowStemLocation_Left;
  21.         m_wndChart.EnableInfoTip(TRUE, &infoTipOptions);//显示提示文本;
  22.         CBCGPChartVisualObject* pChart = m_wndChart.GetChart();//获取图表指针;
  23.         BCGPChartCategory style = BCGPChartArea3D;
  24.         BCGPChartType type = BCGP_CT_SIMPLE;  
  25.         pChart->SetChartType(style,type);//图表类型设置;
  26.         pChart->SetChartTitle(_T("3D面积图表"));//设置图表标题;
  27.         pChart->SetSeriesShadow(true);//数据系列显示阴影;
  28.         pChart->ShowDataMarkers(true, 5, BCGPChartMarkerOptions::MS_CIRCLE);//o数据标志点设置;
  29. //        pChart->ShowDataLabels(true, TRUE, TRUE, 45);//数据标签默认不显示;
  30.         pChart->SetThemeOpacity(70);//透明度设置;
  31.         pChart->SetCurveType(BCGPChartFormatSeries::CCT_SPLINE);//设置数据系列曲线样式;
  32.         //创建数据系列,添加数据;
  33.         CBCGPChartSeries* pSeries1 = pChart->CreateSeries(_T("第一年"));
  34.         CBCGPChartSeries* pSeries2 = pChart->CreateSeries(_T("第二年"));
  35.         CBCGPChartSeries* pSeries3 = pChart->CreateSeries(_T("第三年"));
  36.         COleDateTime today = COleDateTime::GetCurrentTime();

  37.         double arTemp[] = { 5., 12., 19, 22, 19, 24, 22, 24, 18, 14, 10, 7 };
  38.         for (int nMonth = 1; nMonth <= 12; nMonth++)
  39.         {
  40.                 COleDateTime date (today.GetYear(), nMonth, 1, 0, 0, 0);
  41.                 CString strMonth = date.Format(_T("%b"));
  42.                 pSeries1->AddDataPoint(strMonth, arTemp[nMonth - 1]);
  43.                 pSeries2->AddDataPoint((int)(arTemp[nMonth - 1] + Rand(-5, 5)));
  44.                 pSeries3->AddDataPoint((int)(arTemp[nMonth - 1] + Rand(-5, 5)));
  45.         }
  46.         //添加添加到布局管理器统一管理布局;
  47.         if (GetLayout() == NULL)
  48.                 return bRst;
  49.         CBCGPStaticLayout* pLayout = (CBCGPStaticLayout*)GetLayout();
  50.         if (pLayout == NULL)
  51.                 return bRst;
  52.         pLayout->AddAnchor(m_wndChart.GetDlgCtrlID(), CBCGPStaticLayout::e_MoveTypeNone, CBCGPStaticLayout::e_SizeTypeBoth);
  53.         //
  54.         return bRst;
  55. }
复制代码
添加图表旋转控件的点击函数,用于旋转图表。
  1. void CMy123View::OnRotate()
  2. {
  3.         RotateChart(m_wndRotate.GetRotationObject()->GetClicked());
  4. }
复制代码


最后就是图表类型切换与标签设置按钮的实现。
  1. void CMy123View::OnBnClickedButton1()
  2. {
  3.         static int nIndex=1;
  4.         CBCGPChartVisualObject* pChart = m_wndChart.GetChart();//获取图表指针;
  5.         if (nIndex == 0)
  6.         {
  7.                 pChart->SetChartType(BCGPChartArea3D, BCGP_CT_SIMPLE);
  8.         }
  9.         else if (nIndex == 1)
  10.         {
  11.                 pChart->SetChartType(BCGPChartArea3D, BCGP_CT_STACKED);
  12.         }
  13.         else
  14.         {
  15.                 pChart->SetChartType(BCGPChartArea3D, BCGP_CT_100STACKED);
  16.         }
  17.         //设置3D图表背景墙相关属性;
  18.         {
  19.                 CBCGPChartDiagram3D* pDiagram3D = pChart->GetDiagram3D();
  20.                 ASSERT(pDiagram3D != NULL);
  21.                 pDiagram3D->SetDepthScalePercent(2);
  22.                 pDiagram3D->SetFrontDistancePercent(0.5);
  23.                 pDiagram3D->SetHeightScalePercent(1);
  24.                 DWORD dwoFlags = CBCGPChartDiagram3D::DWO_OUTLINE_ALL|CBCGPChartDiagram3D::DWO_DRAW_ALL_WALLS | CBCGPChartDiagram3D::DWO_DRAW_FLOOR;
  25.                 pDiagram3D->SetDrawWallOptions((CBCGPChartDiagram3D::DrawWallOptions)dwoFlags);
  26.                 pDiagram3D->SetThickWallsAndFloor(true);
  27.                
  28.         }
  29.         pChart->Redraw();
  30.         nIndex++;
  31.         nIndex = nIndex>2?0:nIndex;
  32. }


  33. void CMy123View::OnBnClickedButton2()
  34. {
  35.         static int nIndex=0;
  36.         bool bShow = nIndex==8?false:true;
  37.         double dbDegree = 45*nIndex;
  38.         CBCGPChartVisualObject* pChart = m_wndChart.GetChart();
  39.         ASSERT_VALID(pChart);
  40.         pChart->ShowDataLabels(bShow, TRUE, FALSE, dbDegree);
  41.         pChart->Redraw();
  42.         nIndex++;
  43.         nIndex=nIndex>8?0:nIndex;
  44. }
复制代码
例程使用的MFC扩展库可以网站搜索下载。
例程源代码下载地址:
游客,为过滤非法行为,全站隐藏资源仅对充值会员开放进入升级

  

如果您认可,可联系功能定制!

  

如果您着急,充值会员可直接联系发您资料!

  

QQ联系我

微信扫扫联系我

  

  

上位机VC MFC程序开发精典实例大全源码与视频讲解配套下载408例

  

经历1年的编程与录制点击进入查看



回复

使用道具 举报

点击查看
快速回复 返回列表 客服中心 搜索