那位高手知道:
     当MsChart控件设置显示方式为:m_Chart.SetChartType(16)时,只有一个Y轴,能否显示第二Y轴?如何设置和使用?

解决方案 »

  1.   

    记得www.wave12.com的   图表组件wsChart4.0     
      功能强大操作简单好用你可以试   下 
      

  2.   

    ctu_85兄:CMschart的走势图X轴刻度标注数字能否水平显示?
      

  3.   

    ctu_85兄:
          wschart 4.5 折线图X轴刻度标注数字能否水平显示?
      

  4.   

    动态绘制图表实例   
        在一个温度采集系统中,希望把采集来的各项温度值实时显示,用Chart控件绘制曲线走势图:     
      各温度项以不同颜色的曲线表示;     
      横坐标为时间,纵坐标为温度值,均要求滚动显示;     
      在每次采样完成后,刷新屏幕。     
          
        
        设计思路     
        
      随着时间的推移,采集来的数据不断增加,不一定在一屏中显示,所以系统打开一个实时数据库,存放采集来的实时数据。显示时,需要哪个时间段的数据,就从数据库中读取。     
      在对话框资源编辑时,增加水平滚动条和垂直滚动条,以便配合Chart控件进行滚动显示。     
      为对话框启动定时器,按采样间隔进行采样,并刷新屏幕显示。     
        主要相关代码如下:     
        
      BOOL   CAbcDlg::OnInitDialog(){   
              CDialog::OnInitDialog();   
      pDataDB   =   new   dbase;   
      //实时数据记录库,类dbase的基类为CDaoRecordset   
              pDataDB->Open(dbOpenDynaset,   “select   
      *   from   data");   
              VARIANT   var;   
      m_Chart.GetPlot().GetAxis(1,var).GetValueScale().   
          SetAuto(FALSE);//不自动标注y轴刻度   
      m_Chart.GetPlot().GetAxis(1,   var).GetValueScale().   
          SetMaximum(37);//y轴最大刻度   
      m_Chart.GetPlot().GetAxis(1,   var).GetValueScale().   
          SetMinimum(32);//y轴最小刻度   
      m_Chart.GetPlot().GetAxis(1,var).GetValueScale().   
          SetMajorDivision(5);//y轴刻度5等分   
      m_Chart.GetPlot().GetAxis(1,var).GetValueScale().   
          SetMinorDivision(1);//每刻度一个刻度线   
      m_Chart.SetColumnCount(3);   //3个温度项,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(2);//线宽   
            m_Chart.GetPlot().GetSeriesCollection().   
              GetItem(2).GetPen().SetWidth(2);   
            m_Chart.GetPlot().GetSeriesCollection().   
              GetItem(3).GetPen().SetWidth(2);   
            m_Chart.SetRowCount(10);   //一屏显示10个采样时刻   
        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);//每时刻一个刻度线   
                  m_ScrLeft.SetScrollRange(0,45);   
                //垂直滚动条可滚动范围(温度值范围0-50,   
                  每滚动1度,一屏显示5度)   
              m_ScrLeft.SetScrollPos(45-32);//垂直滚动条的当前位置   
              m_ScrBottom.SetScrollRange(0,   0);//水平滚动条的可滚动范围   
              m_ScrBottom.SetScrollPos(0);//水平滚动条的当前位置   
              SetTimer(23,   300000,   NULL);//启动定时器,定时间隔5分钟   
              Sample();//调用采样函数进行第一次采样,并把数据记录入库   
                return   TRUE;       
      }   
      void   CAbcDlg::OnTimer(UINT   nIDEvent)   {   
              Sample();//采样,并把数据记录入库   
              if   (pDataDB->GetRecordCount()>10)   
          theApp.nBottomRange   =   pDataDB->GetRecordCount()-10;   
              else   
      theApp.nBottomRange   =   0;     
      //用全局变量保存水平滚动条的范围值   
      m_ScrBottom.SetScrollRange(0,theApp.nBottomRange);   
              theApp.nBottomPos   =   theApp.nBottomRange;   
            m_ScrBottom.SetScrollPos(theApp.nBottomPos);   
              //修正水平滚动条的显示   
              DrawPic();//调用函数,刷新曲线显示   
        
              CDialog::OnTimer(nIDEvent);   
      }   
      void   CAbcDlg::DrawPic()   {   
      char   s[10];   
              UINT   row   =   1;   
              pDataDB->MoveFirst();   
      pDataDB->Move(theApp.nBottomPos);   
      //只从数据库中取某时间段的数据进行显示   
              while   ((!pDataDB->IsEOF())   &&   (row   <=   10)){   
              m_Chart.SetRow(row);   
      m_Chart.SetRowLabel((LPCTSTR)pDataDB   
      ->m_date_time.Format(“%H:%M"));   
      //以采样时刻做x轴的标注   
              m_Chart.SetColumn(1);   
              sprintf(s,   “%6.2f",   pDataDB->m_No1);   
              m_Chart.SetData((LPCSTR)s);   
              m_Chart.SetColumn(2);   
              sprintf(s,   “%6.2f",   pDataDB->m_No2);   
              m_Chart.SetData((LPCSTR)s);   
              m_Chart.SetColumn(3);   
              sprintf(s,   “%6.2f",   pDataDB->m_No3);   
              m_Chart.SetData((LPCSTR)s);   
              pDataDB->MoveNext();   
              row++;   
              }   
              while   ((row   <=   10)){   
              m_Chart.SetRow(row);   
              m_Chart.SetRowLabel((LPCTSTR)“");   
      m_Chart.GetDataGrid().SetData(row,   1,   0,   1);   
      //采样数据不足10个点,   对应的位置不显示   
              m_Chart.GetDataGrid().SetData(row,   2,   0,   1);   
              m_Chart.GetDataGrid().SetData(row,   3,   0,   1);   
              row++;   
              }   
              m_Chart.Refresh();   
      }   
      void   CAbcDlg::OnHScroll(UINT   nSBCode,     
              UINT   nPos,   CScrollBar*   pScrollBar)   {   
              if   (pDataDB->GetRecordCount()>10)   
          theApp.nBottomRange   =   pDataDB->GetRecordCount()-10;   
              else   
              theApp.nBottomRange   =   0;   
        m_ScrBottom.SetScrollRange(0,   theApp.nBottomRange);   
              switch   (nSBCode){   
              case   SB_LINERIGHT:   
            if   (theApp.nBottomPos   <   theApp.nBottomRange){   
            theApp.nBottomPos   =   theApp.nBottomPos   +   1;   
            m_ScrBottom.SetScrollPos(theApp.nBottomPos);   
              DrawPic();   
              }   
              break;   
              case   SB_LINELEFT:   
              if   (theApp.nBottomPos   >   0){   
            theApp.nBottomPos   =   theApp.nBottomPos   -   1;   
              m_ScrBottom.SetScrollPos(theApp.nBottomPos);   
              DrawPic();   
              }   
              break;   
              }   
              CDialog::OnHScroll(nSBCode,   nPos,   pScrollBar);   
      }   
      void   CAbcDlg::OnVScroll(UINT   nSBCode,     
              UINT   nPos,   CScrollBar*   pScrollBar)   {   
              VARIANT   var;   
              double   max1,min1,f;   
              switch   (nSBCode){   
              case   SB_LINEDOWN:   
      f   =   m_Chart.GetPlot().GetAxis(1,   var).   
          GetValueScale().GetMinimum()   -   1;   
              if   (f>=0)   {//最小刻度大于等于0,   则可以滚动   
      m_Chart.GetPlot().GetAxis(1,   var).GetValueScale().   
          SetMinimum(f);   
      f   =   m_Chart.GetPlot().GetAxis   
        (1,   var).GetValueScale().GetMaximum()   -   1;   
      m_Chart.GetPlot().GetAxis(1,   var).GetValueScale().   
      SetMaximum(f);   
          pScrollBar->SetScrollPos(pScrollBar->GetScrollPos()   +   1);   
              m_Chart.Refresh();   
              }   
              break;   
              case   SB_LINEUP:   
      f   =   m_Chart.GetPlot().GetAxis(1,   var).   
      GetValueScale().GetMaximum()   +   1;   
              if   (f   <=   50)   {//最大刻度小于等于50,   则可以滚动   
      m_Chart.GetPlot().GetAxis   
      (1,   var).GetValueScale().SetMaximum(f);   
      f   =   m_Chart.GetPlot().GetAxis(1,   var).   
      GetValueScale().GetMinimum()   +   1;   
      m_Chart.GetPlot().GetAxis(1,   var).GetValueScale().   
          SetMinimum(f);   
          pScrollBar->SetScrollPos(pScrollBar->GetScrollPos()   -   1);   
              m_Chart.Refresh();   
              }   
              break;   
              }   
              CDialog::OnVScroll(nSBCode,   nPos,   pScrollBar);   
      }   
        
        特别注意,程序中用到的关于控件的类,如CVcAxis等,需要在AbcDlg.cpp文件的开始处说明:#include   “VcAxis.h"。     
        
        限于篇幅,文中仅仅是一个简单示例的部分代码。在实际应用中,一般会有更多的需求,比如:对坐标轴进行缩放显示;采样有可能得不到正确的采样值时曲线显示不连续等等,这时需要根据需求编写相应代码。 
      

  5.   

    计算机世界2000年第29期   
      用Chart控件绘制动态图表   
      

  6.   

    ctu_85兄:
         你的答复我也在网上看过。现在我都能简单使用,能从access数据表读取电压、时间数据在CHART上显示曲线。
         问题是:(1)当设置m_Chart.SetChartType(3),2D线条型显示方式。在一屏显示的点数很多时,X轴刻度比较密时,标注的数字就变成从下到上垂直显示,如何设置水平显示?    (2)当MsChart 设置成2DXY(xy轴形式)型显示方式:m_Chart.SetChartType(3),能X轴能水平显示数据,但是只有一个Y轴,能否显示第二Y轴?
      

  7.   

    ctu_85兄:
           非常感谢你的支持!北京邮电大学刘瑞芳的大作已经拜读。是我至今在网上搜索到关于MSCHATY最详细的资料!
       “记得www.wave12.com的   图表组件wsChart4.0 功能强大操作简单好用你可以试下 ”wsChart4.0 是要付费的。而且它的X轴数字密的时候也是从下到上垂直显示。也不符合我的要求。
      

  8.   

    ctu_85兄:
           ZedGraph能否用在VC++6.0上?
      

  9.   

    我刚刚看了下ZedGraph 主页。
     “...ZedGraph is a set of classes, written in C#...”恐怕在VC++6.0上用不了。口碑不错!开源免费.
      

  10.   

    ctu_85兄:
         ctu_85兄是个古道热肠人。我现在搞单片机,因碰到实际问题而刚学VC。希望以后能多交流。我的e_mail: [email protected]