Teechart在VC++中使用的碎碎念

原创 2016年06月22日 18:47:27

今天再看官网推荐的Teechart的使用方式,感觉他们还是推荐使用VC++6.0的导出头文件格式,来引入所有的类,并操作teechart控件。
All the files necessary can be found under the New VC classes folder below the utilities folder; these files should be copied to your project folder (using Windows Explorer) and then should be added in to the project (in Solution Explorer -> right click over "Source Files" & "Header Files" folders -> Add Existing Item...).

长期使用teechart,2010年之前在Delphi使用,这几年使用的是VC++。有段时间自绘了曲线显示窗口,但是要处理的动作和效果实在是太多了,虽然可以自定义的东西很多,但是工作量实在是太大,现在已经是大龄程序员了,没有那么多的时间和精力去自己画了,只好重用teechart
VS使用上的困惑:有几个软件用的是VS2005及以上版本开发的,但是因为在这些编译器中teechart导出的函数接口有改动,导致编程效率底下,附上VS2005--VS2015的类库导入步骤:
添加相关类MFC Class From Typelib--->add class from registry---->available type libraries选中teechart pro activex control v8,后面会显示具体的注册路径。把接口interfaces IAxes I...之类的全部选中,导入到程序中,就可以使用了。

下面对比VS和VC++6.0的导出文件:

VS版本的导出文件:

// Machine generated IDispatch wrapper class(es) created with Add Class from Typelib Wizard

#import "C:\\Windows\\SysWow64\\TeeChart8.ocx" no_namespace
// CAxes wrapper class

class CAxes : public COleDispatchDriver
{
public:
    CAxes(){} // Calls COleDispatchDriver default constructor
    CAxes(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
    CAxes(const CAxes& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}

    // Attributes
public:

    // Operations
public:

    // IAxes methods
public:
    LPDISPATCH get_Left()
    {
        LPDISPATCH result;
        InvokeHelper(0x1, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
        return result;
    }
    LPDISPATCH get_Right()
    {
        LPDISPATCH result;
        InvokeHelper(0x2, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
        return result;
    }
    LPDISPATCH get_Top()
    {
        LPDISPATCH result;
        InvokeHelper(0x3, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
        return result;
    }
    LPDISPATCH get_Bottom()
    {
        LPDISPATCH result;
        InvokeHelper(0x4, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
        return result;
    }
    BOOL get_Visible()
    {
        BOOL result;
        InvokeHelper(0xa, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
        return result;
    }
    void put_Visible(BOOL newValue)
    {
        static BYTE parms[] = VTS_BOOL ;
        InvokeHelper(0xa, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }
    LPDISPATCH get_Depth()
    {
        LPDISPATCH result;
        InvokeHelper(0x5, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
        return result;
    }
    BOOL get_DrawAxesBeforeSeries()
    {
        BOOL result;
        InvokeHelper(0x6, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
        return result;
    }
    void put_DrawAxesBeforeSeries(BOOL newValue)
    {
        static BYTE parms[] = VTS_BOOL ;
        InvokeHelper(0x6, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }
    long AddCustom(BOOL IsHorizontal)
    {
        long result;
        static BYTE parms[] = VTS_BOOL ;
        InvokeHelper(0x7, DISPATCH_METHOD, VT_I4, (void*)&result, parms, IsHorizontal);
        return result;
    }
    LPDISPATCH get_Custom(long CustomAxisIndex)
    {
        LPDISPATCH result;
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0x8, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, parms, CustomAxisIndex);
        return result;
    }
    long get_CustomCount()
    {
        long result;
        InvokeHelper(0x9, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
        return result;
    }
    void RemoveCustom(long CustomAxisIndex)
    {
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0xb, DISPATCH_METHOD, VT_EMPTY, NULL, parms, CustomAxisIndex);
    }
    void RemoveAllCustom()
    {
        InvokeHelper(0xc, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
    }
    LPDISPATCH get_DepthTop()
    {
        LPDISPATCH result;
        InvokeHelper(0xc9, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
        return result;
    }
    BOOL get_FastCalc()
    {
        BOOL result;
        InvokeHelper(0xca, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
        return result;
    }
    void put_FastCalc(BOOL newValue)
    {
        static BYTE parms[] = VTS_BOOL ;
        InvokeHelper(0xca, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }
    void SetIsometric(long aVertical, long aHorizontal)
    {
        static BYTE parms[] = VTS_I4 VTS_I4 ;
        InvokeHelper(0xcb, DISPATCH_METHOD, VT_EMPTY, NULL, parms, aVertical, aHorizontal);
    }
    void Hide()
    {
        InvokeHelper(0xcc, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
    }
    BOOL get_Behind()
    {
        BOOL result;
        InvokeHelper(0xcd, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
        return result;
    }
    void put_Behind(BOOL newValue)
    {
        static BYTE parms[] = VTS_BOOL ;
        InvokeHelper(0xcd, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
    }

    // IAxes properties
public:

};

VC++6.0的的导出文件如下:

#if !defined(AFX_AXES_H__6F4A532C_9E89_4968_9E14_E83C63437874__INCLUDED_)
#define AFX_AXES_H__6F4A532C_9E89_4968_9E14_E83C63437874__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Machine generated IDispatch wrapper class(es) created by Microsoft Visual C++

// NOTE: Do not modify the contents of this file.  If this class is regenerated by
//  Microsoft Visual C++, your modifications will be overwritten.

// Dispatch interfaces referenced by this interface
class CAxis;

/////////////////////////////////////////////////////////////////////////////
// CAxes wrapper class

class CAxes : public COleDispatchDriver
{
public:
    CAxes() {}        // Calls COleDispatchDriver default constructor
    CAxes(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
    CAxes(const CAxes& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}

// Attributes
public:

// Operations
public:
    CAxis GetLeft();
    CAxis GetRight();
    CAxis GetTop();
    CAxis GetBottom();
    BOOL GetVisible();
    void SetVisible(BOOL bNewValue);
    CAxis GetDepth();
    BOOL GetDrawAxesBeforeSeries();
    void SetDrawAxesBeforeSeries(BOOL bNewValue);
    long AddCustom(BOOL IsHorizontal);
    CAxis GetCustom(long CustomAxisIndex);
    long GetCustomCount();
    void RemoveCustom(long CustomAxisIndex);
    void RemoveAllCustom();
    CAxis GetDepthTop();
    BOOL GetFastCalc();
    void SetFastCalc(BOOL bNewValue);
    void SetIsometric(long aVertical, long aHorizontal);
    void Hide();
    BOOL GetBehind();
    void SetBehind(BOOL bNewValue);
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_AXES_H__6F4A532C_9E89_4968_9E14_E83C63437874__INCLUDED_)

几大变化:

    VC++ 6.0 VS2005及更高版本
  头文件和源文件 axes.h axes.cpp axes.h  
  函数名称1 GetLeft() get_Left()  
  函数返回值1 CAxis LPDISPATCH  
  函数名称2 SetBehind(BOOL bNewValue) put_Behind(BOOL newValue)  
  函数返回值2 void void  

语句的不同

    VC++ 6.0 VS2005及更高版本
  语句1 `mChart.GetAxis().GetLeft().SetVisible(FALSE); ((CAxis)((CAxes)mChart.get_Axis()).get_Left()).put_Visible(FALSE);`  
  语句2 CAxes ChartAxis = mChart.GetAxis(); CAxis asLeft = ChartAxis.GetLeft(); asLeft.SetVisible(FALSE); CAxes ChartAxis = mChart.get_Axis(); CAxis asLeft = ChartAxis.get_Left(); asLeft.put_Visible(FALSE);  

使用高版本的VS导出的头文件使用过程比较繁琐,尤其是返回值,需要查询具体的类型。
官网推荐还是使用VC++6.0的版本,并且附上了一个文件夹,可以直接使用New VC Classes具体的使用过程还是查询Tutorial 15 - MS VC++ Applications

官方文档中几个有用的例子:

标题的更改

#include "Titles.h"
#include "Strings.h"

COleVariant var1(CString ("ACME Monthly Sales"));
COleVariant var2(CString ("Year: 2014"));
CTitles hd = m_Chart.GetHeader();
hd.GetText().Clear();
hd.GetText().Add(*(LPCVARIANT)var1);
hd.GetText().Add(*(LPCVARIANT)var2);

//if items (header lines) already in list (+ alternative COleVariant declare syntax)

m_Chart1.GetHeader().GetText().SetItem(0, COleVariant("ACME Monthly Sales"));
m_Chart1.GetHeader().GetText().SetItem(1, COleVariant("Year: 2014"));

Canvas绘图

#include "Canvas.h"

m_Chart1.GetCanvas().MoveTo(0,0);
m_Chart1.GetCanvas().LineTo(100,100);
m_Chart1.GetCanvas().TextOut(50,50,"My output text");

坐标轴label的文字修改

CString strLabel(*LabelText);
strLabel += " Period";
strLabel.SetSysString(LabelText);

坐标轴label 的数值更改

{
  if (Axis == atLeft)
  {
    *MoreLabels = true;

    //Only label if following cases are true   
    switch( LabelIndex ) 
    {    
      case 0: *LabelValue = 900; break;
      case 2: *LabelValue = 5000; break;
      case 1: *LabelValue = 10000; break;
      default: *MoreLabels=false;
    }
  }
}

界面绘图:

CString text;
  int value1,value2,total;

  value1 = 4;
  value2 = 6;

  total = value1+value2;

  text.Format(_T("Serie : %d"),total);

  m_Chart1.GetCanvas().TextOut(10,10,text));

常量定义部分:官方给出一个头文件TeeChartDefines.h,为什么不能通过添加类的方式引入,原因是MS VC++ doesn't natively support import of TeeChart constants. You need to create you own defines file and #include it in your project. We offer a pre built defines file in the Examples\Visual C++ folder. Including the file in your project will allow you to use constants by name as matching the Enum declarations in the Online help file.

附上几个常见问题的解答:
MicroSoft Visual C++ specific

  • How to use TeeChart constants in MS VC++.
  • Where are descriptions of functions such as GetSeries(), Add() and other similar functions?
  • Changes made at design time with the Chart Editor do not always save.
  • How do I add/change text of the Chart Header and Footer at runtime in MS VC++ ?
  • Can I obtain any additional examples with use of TeeChart Pro for VC++?
版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

图表控件TeeChart安装使用

优秀的图表控件很多,如AnyChart、TeeChart、Highcharts、FusionCharts XT,本文介绍如何在VC6.0上安装使用TeeChart,主要分三步: 第一步:安装TeeC...

MFC TeeChart用法整理 四(保存图片)

TeeChart可以保存多钟格式的图片,bmp、jpeg、pdf、gif等,对于这些功能的定义在CExport类中声明。我们打开CExport类,看看它的成员函数有那些: void Cop...

我是如何成为一名python大咖的?

人生苦短,都说必须python,那么我分享下我是如何从小白成为Python资深开发者的吧。2014年我大学刚毕业..

MFC中使用teechart控件绘制二维及三维图的方法

Teechart控件 Teechart控件是一个绘图控件,常用来绘制折线图,柱状图等图形,同时能绘制三维图形,这里给出一个网上的资料包,大家可以下载,里面有teechart5、teechart8控件...

MFC中利用TeeChart控件完成三维图形绘制

(如需交流,请关注公众号:神马观止) MFC中利用TeeChart控件完成三维图形绘制               前一段时间由于帮一个朋友处理一些数据,需要编写一个最简单的界面,实现数据显示。中间遇...

TeeChart替代品,MFC下好用的高速绘图控件-(Hight-Speed Charting)

也许这是vc下最好最方便的绘图类,它有TeeChart的绘图和操作风格,不用当心注册破解的问题,因为它是开源的。不用打包注册,因为它是封装成类的,能方便扩展继承。vc6.0到vs2010都能使用,而且...

MFC中TeeChart插件绘图

TeeChart绘图:   通过CTchart 的get_SeriesCount函数获得所有图像序列,再全部清除 1.   for(long i = 0;i 2.      {...

matlab中三维图形绘制函数

1.plot3 plot3是最基本的三维图形函数,它将二维plot函数的功能拓展到三维空间,其基本的调用格式为plot3(x1,y1,z1,'图形设置选项1',x2,y2,z2,'图形设置选项2'…...

MFC TeeChart用法整理 三(三维图)

画三维图,就要添加三维类型的序列。         这里我们仍然以折线图作为范例。右击控件选择Properties,在TeeChart Pro Editor选项卡中单击Edit Chart,...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)