今天再看官网推荐的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(, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
LPDISPATCH get_Right()
{
LPDISPATCH result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
LPDISPATCH get_Top()
{
LPDISPATCH result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
LPDISPATCH get_Bottom()
{
LPDISPATCH result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
BOOL get_Visible()
{
BOOL result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}
void put_Visible(BOOL newValue)
{
static BYTE parms[] = VTS_BOOL ;
InvokeHelper(, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
}
LPDISPATCH get_Depth()
{
LPDISPATCH result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
BOOL get_DrawAxesBeforeSeries()
{
BOOL result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}
void put_DrawAxesBeforeSeries(BOOL newValue)
{
static BYTE parms[] = VTS_BOOL ;
InvokeHelper(, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
}
long AddCustom(BOOL IsHorizontal)
{
long result;
static BYTE parms[] = VTS_BOOL ;
InvokeHelper(, DISPATCH_METHOD, VT_I4, (void*)&result, parms, IsHorizontal);
return result;
}
LPDISPATCH get_Custom(long CustomAxisIndex)
{
LPDISPATCH result;
static BYTE parms[] = VTS_I4 ;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, parms, CustomAxisIndex);
return result;
}
long get_CustomCount()
{
long result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
return result;
}
void RemoveCustom(long CustomAxisIndex)
{
static BYTE parms[] = VTS_I4 ;
InvokeHelper(, DISPATCH_METHOD, VT_EMPTY, NULL, parms, CustomAxisIndex);
}
void RemoveAllCustom()
{
InvokeHelper(, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}
LPDISPATCH get_DepthTop()
{
LPDISPATCH result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
BOOL get_FastCalc()
{
BOOL result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}
void put_FastCalc(BOOL newValue)
{
static BYTE parms[] = VTS_BOOL ;
InvokeHelper(, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
}
void SetIsometric(long aVertical, long aHorizontal)
{
static BYTE parms[] = VTS_I4 VTS_I4 ;
InvokeHelper(, DISPATCH_METHOD, VT_EMPTY, NULL, parms, aVertical, aHorizontal);
}
void Hide()
{
InvokeHelper(, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}
BOOL get_Behind()
{
BOOL result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}
void put_Behind(BOOL newValue)
{
static BYTE parms[] = VTS_BOOL ;
InvokeHelper(, 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 >
#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 |
函数名称1 | | get_Left() |
函数返回值1 | | LPDISPATCH |
函数名称2 | | put_Behind(BOOL newValue) |
函数返回值2 | | 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.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(, COleVariant("ACME Monthly Sales"));
m_Chart1.GetHeader().GetText().SetItem(, COleVariant("Year: 2014"));
Canvas绘图
#include "Canvas.h"
m_Chart1.GetCanvas().MoveTo(,);
m_Chart1.GetCanvas().LineTo(,);
m_Chart1.GetCanvas().TextOut(,,"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 : *LabelValue = ; break;
case : *LabelValue = ; break;
case : *LabelValue = ; break;
default: *MoreLabels=false;
}
}
}
界面绘图:
CString text;
int value1,value2,total;
value1 = ;
value2 = ;
total = value1+value2;
text.Format(_T("Serie : %d"),total);
m_Chart1.GetCanvas().TextOut(,,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++?