图表控件--MSChart(2)

  • 碰到一个东西要用MSChart控件的,呵呵,这不就学了怎么用哈!   
  • void CMoreDMcode::OnCacluteDelta(int nRow)   
  • {  
  •  m_Chart.SetRedraw(false);   
  •  m_Chart.SetRow(1);  
  •  for(int i=1;i<=64;i++)  
  •  {  
  •   m_Chart.GetDataGrid().SetData(i,1,nDelta[i-1],0);  
  •  }  
  •  CRgn rgn;   
  •  m_Chart.GetUpdateRgn(&rgn);   
  •  m_Chart.SetRedraw(true);   
  •  m_Chart.InvalidateRgn(&rgn,false) ;  
  • }  
  • void CMoreDMcode::InitChart()  
  • {  
  •  VARIANT var;  
  •  m_Chart.SetColumnCount(1); //设置曲线条数   
  •  m_Chart.SetRowCount(64); //一条曲线有64个点    
  •  m_Chart.SetTitleText("二位形态码△t变化趋势");  
  •  m_Chart.SetChartType(1|2);//   
  •  //m_Chart.SetShowLegend(TRUE);   
  •   
  •  //设置X轴   
  •  m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetAuto(FALSE); // 不自动标注X轴刻度   
  •  m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetDivisionsPerLabel(8);// 每四刻度一个标注   
  •  m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetDivisionsPerTick(8);  // 每刻度一个刻度线   
  •  //m_Chart.GetPlot().GetAxis(0,var).GetValueScale().SetMinorDivision(1); // 每刻度一个刻度线   
  •  m_Chart.GetPlot().GetAxis(0,var).GetValueScale().SetMaximum(64); // X轴最大刻度   
  •  m_Chart.GetPlot().GetAxis(0,var).GetValueScale().SetMinimum(0); // X轴最小刻度   
  •  m_Chart.GetPlot().GetAxis(0,var).GetAxisTitle().SetText("二位形态码");  
  •  //设置Y轴   
  •  m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetAuto(FALSE); // 不自动标注Y轴刻度   
  •  m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMaximum(100); // Y轴最大刻度   
  •  m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMinimum(0); // Y轴最小刻度   
  •  m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMajorDivision(10); // Y轴刻度10等分   
  •  m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMinorDivision(1); // 每刻度一个刻度线   
  •  //m_Chart.GetPlot().GetAxis(1,var).GetAxisTitle().SetText("△t变化趋势"); // Y轴名称   
  •  //m_Chart.GetPlot().GetAxis(1,var).GetAxisTitle().GetTextLayout().SetOrientation(2);//Y轴名称排列方式   
  •  m_Chart.GetPlot().SetUniformAxis(FALSE);  
  •   
  • }  
  • void CMoreDMcode::OnMSChartDraw()   
  • {  
  •  CString str;  
  •  int nRow = m_Grid.GetFocusCell().row;  
  •  if (nRow<0)  
  •  {  
  •   MessageBox("请在左表选择要排序的行!","操作错误",MB_OK|MB_ICONWARNING);  
  •   return;  
  •  }  
  •  for(int i=0;i<64;i++)  
  •  {  
  •   str = m_Grid.GetItemText(nRow,i+3);  
  •   nDelta[i] = atoi(str.GetBuffer(0));  
  •  }  
  •  InitChart();//初始化坐标轴   
  •  // 根据不同的数据设定不同的Y轴最大刻度   
  •  int m = GetMaxData(nDelta);  
  •  m=(m/50)*50+50;//取靠近M的比M大的50的倍数   
  •  str = m_Grid.GetItemText(nRow,0);  
  •  VARIANT var;  
  •  m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMaximum(m);   
  •    
  •  OnCacluteDelta(nRow);//绘图   
  •  str = "当前绘制的是第"+str+"期的△t变化趋势";  
  •  m_Tip.SetWindowText(str);  
  • }  
  • 函数名字取得不好,大家见笑了,开始取名字错误,后来不想该了,呵呵^_^  
  • ====================================================  
  • 图表由于其直观明了的特性,在实际应用中十分很广泛。我们常常希望数据能通过图表来显示其特性。例如在Delphi和C++Builder编程中,我们可以很方便地实现数据图表。MsChart(6.0或5.0版)是Windows系统中Visual studio自带的一个ACTIVEX控件,它功能强大,应用广泛,具有以下特点:  
  • · 支持随机数据和随机数组,动态显示。   
  • · 支持所有主要的图表类型。   
  • · 支持三维显示。   
  • MsChart具有45个属性,9个方法,49 事件,可灵活编程,可实现各类表的显示。  
  • 1 MsChart 应用编程   
  • 首先插入MsChart 控件,  
  • 在工程中加入 mschart  
  • 菜单->Project->Add To Project->Components and Controls->Registered ActiveX Controls->Microsoft Chart Control, version 6.0 (OLEDB)  
  • 1.1 坐标系属性的设置   
  • a)纵轴初始化属性  
  • Mschart 默认支持自动标准,将自动调整,可以缺省设置。  
  • #include "mschart.h" //添加相关的头文件   
  • #include "VcAxis.h"   
  • #include "VcAxisTitle.h"   
  • #include "VcTextLayout.h"   
  • #include "VcDataGrid.h"   
  • #include "VcPlot.h"   
  • #include "VcValueScale.h"   
  • #include "VcSeriesCollection.h"   
  • #include "VcSeries.h"   
  • #include "VcPen.h"   
  • #include "VcCategoryScale.h"   
  • #include "VcColor.h"   
  • #include "VcDataGrid.h"   
  • #include "VcBackdrop.h"   
  • #include "VcFill.h"   
  • #include "VcBrush.h"   
  • #include "VcDataPoints.h"   
  • #include "VcDataPoint.h"   
  • #include "VcDataPointLabel.h"   
  • #include "VcAxisTitle.h"   
  • //最好添加全部头函数,   
  • CMSChart m_Chart;//m_Chart 为图表变量   
  • VARIANT var;  
  • m_Chart.GetPlot().GetAxis(1,var)//获取纵轴   
  • //设置是否支持自动标准;控件默认支持自动标准。   
  • m_Chart.GetPlot().GetAxis().GetValuesScale().SetAuto(FALSE);  
  • //设置最大刻度为M;   
  • m_Chart.GetPlot().GetAxis().GetValuesScale().SetMaximum(M);  
  • //设置最小刻度为m;   
  • m_Chart.GetPlot().GetAxis().GetValuesScale().SetMinimum(m);  
  • //设置轴的等分数D;   
  • m_Chart.GetPlot().GetAxis().GetValuesScale().SetMajorDivision(D);  
  • //设置每等分的刻度线数n;   
  • m_Chart.GetPlot().GetAxis().GetValuesScale().SetMinorDivision(n);  
  • b)横轴初始化属性  
  • VARIANT var;  
  • m_Chart.GetPlot().GetAxis(0,var)//获取横轴   
  • 其他属性设置跟纵轴相同。  
  • 1.2 数据显示  
  • a)设置标题栏和标签  
  • m_Chart.SetTitleText(“标题”);//设置标题栏   
  • m_Chart.SetRowLabel((“第I行”);//设置第i行标签   
  • m_Chart.SetColumnLabel((“第j列”);//设置第j列标签   
  • b)行列的显示布局  
  • MSChart的行列显示布局有其自身的特点:下面显示是一个行列4×3(矩形图),即(四行,三列)的布局示意图。  
  • m_Chart.SetRowCount(4); //没条曲线三个四个点 (曲线图)   
  • m_Chart.SetColumnCount(3); //设置曲线条数为三条(曲线图)   
  • c)行列操作  
  • // 操作行列第i行、第j列   
  • m_Chart.SetRow(i);// 第i行   
  • m_Chart.SetColumn(j);//第j行   
  • m_Chart.SetRowLabel((“第i行”);//设置第i行标签   
  • CString str=”90.5”;  
  • m_Chart.SetData((LPCTSTR(str)); //设置行列,j>的显示数据   
  • m_Chart.Refresh();//刷新视图   
  • d)显示方式  
  • 获取当前的显示方式:  
  • long nType =m_Chart.GetChartType();  
  • 设置显示方式:  
  • m_Chart.SetChartType(0);//3D(三维) 显示   
  • m_Chart.SetChartType(1);//2D(二维) 显示   
  • m_Chart.Refresh();  
  • 其它常用组合方式为:  
  • m_Chart.SetChartType(1|0) //2D柱(条)形,   
  • m_Chart.SetChartType(0|0) //3D柱(条)形   
  • m_Chart.SetChartType(1|2) //2D线条型   
  • m_Chart.SetChartType(0|2) //3D线条型   
  • m_Chart.SetChartType(1|4) //2D区域型   
  • m_Chart.SetChartType(0|4) //3D区域型   
  • m_Chart.SetChartType(1|6) //2D阶梯型   
  • m_Chart.SetChartType(0|6) //3D阶梯型   
  • m_Chart.SetChartType(1|8) //2D复(混)合型   
  • m_Chart.SetChartType(0|8) //3D复(混)合型   
  • 另外,在2D方式中,还有两类:饼型和XY型  
  • m_Chart.SetChartType(14) //2D 饼型   
  • m_Chart.SetChartType(16) //2DXY型   
  • e)其他  
  • 其他属性,比如设置字体,颜色,对齐方式等。  
  • //====================================================   
  • //VC知识库上的参考文章   
  • http://www.vckbase.com/document/viewdoc/?id=959   
  •   
  • 3.3 设置 m_Chart void CDemoView::InitChart()  
  • {  
  •  // 设置标题   
  •  m_Chart.SetTitleText("mschart 示例 by thinkry@263.net");  
  •  // 下面两句改变背景色   
  •  m_Chart.GetBackdrop().GetFill().SetStyle(1);  
  •  m_Chart.GetBackdrop().GetFill().GetBrush().GetFillColor().Set(255, 255, 255);  
  •  // 显示图例   
  •  m_Chart.SetShowLegend(TRUE);  
  •  m_Chart.SetColumn(1);  
  •  m_Chart.SetColumnLabel((LPCTSTR)"1号机");  
  •  m_Chart.SetColumn(2);  
  •  m_Chart.SetColumnLabel((LPCTSTR)"2号机");  
  •  m_Chart.SetColumn(3);  
  •  m_Chart.SetColumnLabel((LPCTSTR)"3号机");  
  •  // 栈模式   
  •  // m_Chart.SetStacking(TRUE);   
  •  // Y轴设置   
  •  VARIANT var;  
  •  m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetAuto(FALSE); // 不自动标注Y轴刻度   
  •  m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMaximum(100); // Y轴最大刻度   
  •  m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMinimum(0); // Y轴最小刻度   
  •  m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMajorDivision(5); // Y轴刻度5等分   
  •  m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMinorDivision(1); // 每刻度一个刻度线   
  •  m_Chart.GetPlot().GetAxis(1,var).GetAxisTitle().SetText("小时"); // Y轴名称   
  •  // 3条曲线   
  •  m_Chart.SetColumnCount(3);   
  •  // 线色   
  •  m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetPen().GetVtColor().Set(0, 0, 255);  
  •  m_Chart.GetPlot().GetSeriesCollection().GetItem(2).GetPen().GetVtColor().Set(255, 0, 0);  
  •  m_Chart.GetPlot().GetSeriesCollection().GetItem(3).GetPen().GetVtColor().Set(0, 255, 0);  
  •  // 线宽(对点线图有效)   
  •  m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetPen().SetWidth(50);  
  •  m_Chart.GetPlot().GetSeriesCollection().GetItem(2).GetPen().SetWidth(100);  
  •  m_Chart.GetPlot().GetSeriesCollection().GetItem(3).GetPen().SetWidth(2);  
  •  // 数据点类型显示数据值的模式(对柱柱状图和点线图有效)   
  •  // 0: 不显示 1: 显示在柱状图外   
  •  // 2: 显示在柱状图内上方 3: 显示在柱状图内中间 4: 显示在柱状图内下方   
  •  m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);  
  •  m_Chart.GetPlot().GetSeriesCollection().GetItem(2).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);  
  •  m_Chart.GetPlot().GetSeriesCollection().GetItem(3).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);  
  • }       
  • 3.4 设置数据 void CDemoView::DrawChart()  
  • {  
  •  int nRowCount = 6;  
  •  m_Chart.SetRowCount(nRowCount);  
  •  VARIANT var;  
  •    
  •  // 不自动标注X轴刻度   
  •  m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetAuto(FALSE);   
  •    
  •  // 每刻度一个标注   
  •  m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetDivisionsPerLabel(1);  
  •    
  •  // 每刻度一个刻度线   
  •  m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetDivisionsPerTick(1);   
  •    
  •  // X轴名称   
  •  m_Chart.GetPlot().GetAxis(0,var).GetAxisTitle().SetText("日期");   
  •  char buf[32];  
  •  srand( (unsigned)time( NULL ) );  
  •  for(int row = 1; row <= nRowCount; ++row)  
  •  {  
  •   m_Chart.SetRow(row);  
  •   sprintf(buf, "%d号", row);  
  •   m_Chart.SetRowLabel((LPCTSTR)buf);  
  •   m_Chart.GetDataGrid().SetData(row, 1, rand() * 100 / RAND_MAX, 0);//设置第一条曲线的第row个点   
  •   m_Chart.GetDataGrid().SetData(row, 2, rand() * 100 / RAND_MAX, 0);//设置第二条曲线的第row个点   
  •   m_Chart.GetDataGrid().SetData(row, 3, rand() * 100 / RAND_MAX, 0);//设置第三条曲线的第row个点   
  •  }  
  •  m_Chart.Refresh();   
  • }  
  • /* 
  • SetData (row, column, dataPoint, nullFlag) 
  • SetData 方法语法包括以下组成部分: 
  •  
  • row Integer 类型。标识包含数据点值的行。  
  • column Integer 类型。标识包含数据点值的列。  
  • dataPoint Double 类型。数据点值。  
  • nullFlag Integer 类型。指示数据点值是否为空  
  • */  
  • 3.5 改变显示类型 // 折线图   
  • void CDemoView::OnChartLine()   
  • {  
  •  m_Chart.SetChartType(3);   
  •  DrawChart();  
  • }  
  • // 柱状图    
  • void CDemoView::OnChartCombi()   
  • {  
  •  m_Chart.SetChartType(1);   
  •  DrawChart();  
  • }  
  • // 饼状图   
  • void CDemoView::OnChartPie()   
  • {  
  •  m_Chart.SetChartType(14);   
  •  DrawChart();  
  • }  
  •   
  • 源文档 <http://wq2325.bokee.com/3319283.html>    
  •   
  •   
  • 1.         在工程中添加MSChart控件  
  • Project—〉Add to Project—〉Registered ActiveX Controls,选中Microsoft Chart Control 6.0(SP4)(OLEDB)  
  • 点击Insert,一路确定  
  • 2.         在用到控件的地方加上相应的头文件,mschart.h,还有其他比较常用的头文件:#include "VcPlot.h"  
  • #include "VcAxis.h"   
  • #include "VcValueScale.h"   
  • #include "VcSeriesCollection.h"   
  • #include "VcSeries.h"   
  • #include "VcPen.h"   
  • #include "VcCategoryScale.h"   
  • #include "VcColor.h"   
  • #include "VcDataGrid.h"   
  • #include "VcBackdrop.h"   
  • #include "VcFill.h"   
  • #include "VcBrush.h"   
  • #include "VcDataPoints.h"   
  • #include "VcDataPoint.h"   
  • #include "VcDataPointLabel.h"   
  • #include "VcAxisTitle.h"   
  • #include "VcAxisScale.h"   
  • #include "VcAxisGrid.h"   
  • 3.         定义并create控件对象  
  • CMSChart m_Chart;  
  • m_Chart.Create("mschart", WS_CHILD| WS_VISIBLE, rc, this, 10);// this 为窗口指针   
  • 4.         设置控件的属性  
  • //设置标题   
  •        m_Chart.SetTitleText(Title);//Title 为CString类型   
  • //设置栈模式   
  •        m_Chart.SetStacking(FALSE);  
  • //设置行数及列数   
  • m_Chart.SetRowCount(iRowCount);//iRowCount和iColumnCount为int型   
  • m_Chart.SetColumnCount(iColummCount);  
  • //设置控件的数据,int型的iRow,iColumn可看成是数据所在的行和列,Data即是所要设的数值型数据   
  •        m_Chart.GetDataGrid().SetData(iRow, iColumn, Data, 0);  
  • //设置图例   
  •        m_Chart.SetShowLegend(TRUE);//显示图例   
  •        m_Chart.SetColumn(iColumn);  
  •        m_Chart.SetColumnLabel(slegend);//slegend为CString型   
  • //设置x轴下方显示的标记   
  •        m_Chart.SetRow(iRow);  
  •        m_Chart.SetRowLabel(sLabel);//sLabel为CString型   
  • //设置x轴及y轴的标题。xTitle和yTitle为CString型   
  •        m_Chart.GetPlot().GetAxis(0,var).GetAxisTitle().SetText(xTitle); //x轴   
  •        m_Chart.GetPlot().GetAxis(1,var).GetAxisTitle().SetText(yTitle); //y轴   
  • //设置控件类型   
  •        m_Chart.SetChartType(3);//3:曲线型;1:条形;14:饼图   
  • //设置背景颜色   
  •        m_Chart.GetBackdrop().GetFill().SetStyle(1);  
  •        m_Chart.GetBackdrop().GetFill().GetBrush().GetFillColor().Set(255, 255, 255);  
  • //设置数据系列的颜色:如果是曲线图则对应每条曲线的颜色   
  •        for (int i = 1; i <= m_Chart.GetColumnCount(); i++ )  
  •        {//这里设置为随机颜色   
  •               m_Chart.GetPlot().GetSeriesCollection().GetItem(i).GetPen().GetVtColor().Set(rand() * 230 / RAND_MAX, rand() * 230 / RAND_MAX, rand() * 230 / RAND_MAX);  
  •               m_Chart.GetPlot().GetSeriesCollection().GetItem(i).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);  
  •        }  
  • //设置x轴的其他属性   
  •        m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetAuto(FALSE); // 不自动标注X轴刻度   
  •        m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetDivisionsPerLabel(1);// 每刻度一个标注   
  •        m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetDivisionsPerTick(1); // 每刻度一个刻度线   
  • //自动标注y轴   
  •        m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetAuto(TRUE);   
  • 在这里,也可以手动设置y轴,如下:  
  • m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMaximum(100);     // y轴最大刻度为100   
  • m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMinimum(0);         // y轴最小刻度为0   
  • m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMajorDivision(5);   // 将y轴刻度5等分   
  • m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMinorDivision(1);   // 每刻度一个刻度线   
  • m_Chart.GetPlot().GetAxis(1,var).GetAxisTitle().SetText("YourTitle");     // y的轴名称   
  •    
  • //不要与x轴垂直的表格线   
  •        m_Chart.GetPlot().GetAxis(0,var).GetAxisGrid().GetMajorPen().SetStyle(0);// no x grids   
  • //隐藏第二y轴,即右边的y轴   
  •        m_Chart.GetPlot().GetAxis(2,var).GetAxisScale().SetHide(TRUE);  
  • //刷新控件   
  •        m_Chart.Refresh();  
  •   
  • 源文档 <http://blog.csdn.net/qlping2007/archive/2008/03/21/2201719.aspx>    
  •   
  •   
  •   
  •   
  •     MSChart制图类  
  •   
  •   
  •     添加MSChart控件  
  •     MSChart是VC++6.0中自带的一个特殊控件类,用于绘制坐标曲线图。如果要使用这个控件,则可以按下图的示意进行添加此控件。  
  •       
  •       
  •   
  •   
  •   
  •     MSChart控件的使用方法  
  •     首先在要使用的类的实现文件中包含如下头文件:  
  • #include "VcPlot.h"   
  • #include "VcAxis.h"   
  • #include "VcValueScale.h"   
  • #include "VcSeriesCollection.h"   
  • #include "VcSeries.h"   
  • #include "VcPen.h"   
  • #include "VcCategoryScale.h"   
  • #include "VcColor.h"   
  • #include "VcDataGrid.h"   
  • #include "VcBackdrop.h"   
  • #include "VcFill.h"   
  • #include "VcBrush.h"   
  • #include "VcDataPoints.h"   
  • #include "VcDataPoint.h"   
  • #include "VcDataPointLabel.h"   
  • #include "VcAxisTitle.h"   
  • #include "math.h"   
  •     在要使用的类的头文件中包含:  
  • #include "mschart.h"       
  •     本系统中按照如下函数调用来实现MSChart类绘制故障树重要度曲线的功能(CDrawImp是调用MSChart的类)。  
  •   
  •   
  •     类中变量定义  
  • class CDrawImp : public CDialog  
  • {  
  • // Construction   
  • public:  
  •     void DrawChart(int type);  
  •     void initmschart();  
  •     CMSChart m_Chart;  
  •     ……  
  • }  
  •   
  •   
  •     类中MSChart的初始化函数  
  • void CDrawImp::initmschart()  
  • {  
  •     // 下面两句改变背景色   
  •     m_Chart.GetBackdrop().GetFill().SetStyle(1);  
  •     // 显示图例   
  •     m_Chart.SetShowLegend(FALSE);  
  •     m_Chart.SetColumn(1);  
  •     m_Chart.SetChartType(3);  
  •    
  •     // 栈模式   
  •     m_Chart.SetStacking(FALSE);  
  •    
  •     // Y轴设置   
  •     VARIANT var;  
  • //不自动标注Y轴刻度   
  •     m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetAuto(FALSE);          
  • //Y轴刻度10等分   
  •     m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMajorDivision(10);   
  • //每刻度一个刻度线   
  •     m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMinorDivision(1);      
  • //不自动标注X轴刻度   
  •     m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetAuto(FALSE);      
  • //每刻度一个标注           
  •     m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetDivisionsPerLabel(0);   
  • //每刻度一个刻度线   
  •     m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetDivisionsPerTick(1);   
  •     m_Chart.GetPlot().GetAxis(0,var).GetAxisTitle().SetText("基本故障事件(对应表2中的序号)");// X轴名称   
  •    
  •     // 1条曲线   
  •     m_Chart.SetColumnCount(1);   
  •     // 数据点类型显示数据值的模式(对柱柱状图和点线图有效)   
  •     // 0: 不显示    1: 显示在柱状图外   
  •     // 2: 显示在柱状图内上方    3: 显示在柱状图内中间    4: 显示在柱状图// 内下方   
  •     m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(0);  
  • }  
  •    
  • void CDrawImp::DrawChart(int type)  
  • {  
  •     int nRowCount =bs.FactDictoryList.GetCount();  
  •     VARIANT var;  
  •     m_Chart.SetRowCount(nRowCount);  
  •     m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetPen().GetVtColor().Set(0, 0, 255);  
  •     char buf[32];  
  •    
  • /*    double max = 0.0; 
  •     double min = 10.0; 
  •     double temp; 
  •     for (int i=0; i<nRowCount; i++) 
  •     { 
  •         switch(type) 
  •         { 
  •         case 0: 
  •             temp = bs.FactDictoryList.GetAt(bs.FactDictoryList.FindIndex(i)).FactCF; 
  •             break; 
  •         case 1: 
  •             temp = bs.FactDictoryList.GetAt(bs.FactDictoryList.FindIndex(i)).cfimportance; 
  •             break; 
  •         case 2: 
  •             temp =bs.FactDictoryList.GetAt(bs.FactDictoryList.FindIndex(i)).structimportance; 
  •             break; 
  •         case 3: 
  •             temp = bs.FactDictoryList.GetAt(bs.FactDictoryList.FindIndex(i)).edgeimportance; 
  •             break; 
  •         default: 
  •             break; 
  •         } 
  •         if (max < temp) 
  •             max = temp; 
  •         if (min > temp) 
  •             min = temp; 
  •     }*/  
  •     m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMaximum(10);    // Y轴最大刻度   
  •     m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMinimum(0);        // Y轴最小刻度   
  •     double c;  
  •     for(int row = 1; row <= nRowCount; ++row)  
  •     {  
  •         m_Chart.SetRow(row);  
  •         sprintf(buf, "%d", row);  
  •         m_Chart.SetRowLabel((LPCTSTR)buf);  
  •         switch(type)  
  •         {  
  •         case 0:  
  •     c =bs.FactDictoryList.GetAt(bs.FactDictoryList.FindIndex(row-1)).FactCF;  
  •             m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetPen().GetVtColor().Set(0, 0, 255);  
  •             // Y轴名称   
  •                      m_Chart.GetPlot().GetAxis(1,var).GetAxisTitle().SetText("基本事件概率(-lg)");  
  •             break;  
  •         case 1:  
  •             c =bs.FactDictoryList.GetAt(bs.FactDictoryList.FindIndex(row-1)).cfimportance;  
  •             m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetPen().GetVtColor().Set(255, 0, 0);     // Y轴名称       
  •                     m_Chart.GetPlot().GetAxis(1,var).GetAxisTitle().SetText("概率重要度(-lg)");   
  •             break;  
  •         case 2:  
  •         c = bs.FactDictoryList.GetAt(bs.FactDictoryList.FindIndex(row-1)).structimportance;  
  •             m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetPen().GetVtColor().Set(0, 255, 0);       
  • //Y轴名称   
  •             m_Chart.GetPlot().GetAxis(1,var).GetAxisTitle().SetText("结构重要度");   
  •             break;  
  •         case 3:  
  •             c = bs.FactDictoryList.GetAt(bs.FactDictoryList.FindIndex(row-1)).edgeimportance;  
  •         m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetPen().GetVtColor().Set(255, 0, 255);  
  •             // Y轴名称   
  •        m_Chart.GetPlot().GetAxis(1,var).GetAxisTitle().SetText("临界重要度(-lg)");   
  •             break;  
  •         default:  
  •             break;  
  •         }      
  •         m_Chart.GetDataGrid().SetData(row, 1, -log10(c), 0);  
  • }  
  •     m_Chart.Refresh();      
  • }  
  •   
  •   
  •     添加ON_SIZE消息响应函数  
  • void CDrawImp::OnSize(UINT nType, int cx, int cy)   
  • {  
  •     CDialog::OnSize(nType, cx, cy);  
  •     if( m_Chart.GetSafeHwnd() )  
  •         m_Chart.MoveWindow( 0, 0, cx, cy );      
  • }  
  •   
  •   
  •     CDrawImp的OnInitDialog函数种创建MSChart  
  • BOOL CDrawImp::OnInitDialog()   
  • {  
  •     CDialog::OnInitDialog();  
  •    
  • m_radio = 0;  
  •     m_combo.SetCurSel(0);  
  •     UpdateData(FALSE);  
  •     CRect rc;  
  •     GetClientRect(&rc);  
  •     rc.top += 80;  
  •     rc.bottom -= 15;  
  •     rc.left += 15;  
  •     rc.right -= 15;  
  •     m_Chart.Create("mschart", WS_CHILD| WS_VISIBLE, rc, this, 10);  
  •     initmschart();  
  •     DrawChart(0);  
  •    
  •     CString s;  
  •     s.Format("顶事件发生概率为: %f",topcf);  
  •     GetDlgItem(IDC_TOPCFSTATIC)->SetWindowText(s);  
  •    
  •     return TRUE; // return TRUE unless you set the focus to a control   
  •     // EXCEPTION: OCX Property Pages should return FALSE   
  • }  
  •   
  • 源文档 <http://blog.csdn.net/andy8205/archive/2007/11/23/1900008.aspx> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值