首页 > 其他分享 >略谈teechart

略谈teechart

时间:2022-12-23 18:00:35浏览次数:33  
标签:控件 略谈 val Series teechart include YValues XValues


VC,BCB下的曲线图形显示可以自己编写代码,主要是GDI(+)的WinAPI函数,主要是MoveTo和LineTo等函数,自己编写很繁琐。

 最好是用第三方控件,当然VC高版本也提供了MsChart,很强大,本人在C#里用过,主要是C#效率不高,编写的程序太大,还是用VC了.

第三方控件有ntGraph,优点是小巧,只有几个类,缺点不能缩放等;而teechart则给出强大,但是他比较庞大,有几十个类。顺便说下BCB自带有这个控件。

使用比较简单,当然也要花几个小时功夫。讲几个需要注意的地方吧。

1.先注册, regsvr32 teechart8.ocx;再在工程添加,在对话框上右键插入teechart控件;再设置属性,添加曲线等;再添加控件变量,添加头文件

#include "tchart.h"
#include "scroll.h"
#include "Series.h"
#include "Axis.h"
#include "page.h"
#include "ValueList.h"
#include "ToolList.h"
#include "Tools.h"
#include "AnnotationTool.h"
#include "Axes.h"

2.由于添加后类比较多,可以在ClassView中新建一个文件夹存放类。

3.常用代码:

m_chart.Series(0).FillSampleValues(50);//添加sample点

m_chart.Series(0).AddXY(i,arr[i],NULL,RGB(0,0,0));//添加点,效率较低,可用AddArray函数

m_chart.Series(0).Clear();//清空曲线

m_chart.Series(i).SetActive(false);//隐藏显示曲线, true显示

void CTeeChartDlg::OnBnClickedButtondraw2()

{


    CSeries ChartSpeed = (CSeries)m_Chart.Series(0);


    UpdateData(TRUE);


    if (m_nPointNum<=0)


    {


        MessageBox(_T("数据点数不能小于0"));


        return;


    }


    DWORD dwTimeS,dwTimeE;


    CString str(_T(""));


    long i(0);


    double val;




    COleSafeArray XValues;    


    COleSafeArray YValues;


    DWORD pNumElements[] = {m_nPointNum};


    XValues.Create(VT_R8, 1, pNumElements);    


    YValues.Create(VT_R8, 1, pNumElements);


    for(i=0; i<m_nPointNum; i++) 


    {         


        val = i;


        XValues.PutElement(&i, &val);


        val = randf(-20,20);


        YValues.PutElement(&i, &val);


    };


    //由于需要计算时间,画图就不在第一个for循环里实现了


    dwTimeS = GetTickCount();


    ChartSpeed.Clear();


    ChartSpeed.AddArray(m_nPointNum,YValues,XValues);


    dwTimeE = GetTickCount();


    dwTimeE -= dwTimeS;




    str.Format(_T("耗时:%d ms"),dwTimeE);


    SetDlgItemText(IDC_STATIC_T,str);


}


void DrawLine(double* pX,double* pY,long nNum) 


{


    COleSafeArray XValues;    


    COleSafeArray YValues;


    long i(0);


    DWORD wLength = nNum;


    XValues.Create(VT_R8, 1, &wLength);    


    YValues.Create(VT_R8, 1, &wLength);




    for(i=0; i<nNum; i++) 


    {         


        XValues.PutElement(&i, pX+i);


        YValues.PutElement(&i, pY+i);


    }


    CSeries Chart = (CSeries)m_Chart.Series(0);


    Chart.Clear();


    Chart.AddArray(nNum,YValues,XValues);


}

 (pMsg->message == WM_KEYDOWN)  


    {  


        switch(pMsg->wParam)  


        {  


            case VK_ESCAPE: //Esc按键事件  


                return true;  


            case VK_RETURN: //Enter按键事件  


                return true;  


            default:  


                ;  


        }  


    }  

//

标签:控件,略谈,val,Series,teechart,include,YValues,XValues
From: https://blog.51cto.com/u_15045304/5966119

相关文章