今天再看官网推荐的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导出的函数接口有改动,导致变成效率底下:
添加相关类MFC Class From Typelib--->add class from registry---->available type libraries选中teechart pro activex control v8,后面会显示具体的注册路径。把接口interfaces IAxes之类的全部选中,导入到程序中,就可以使用了。导出文件举例如下:
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++?
网友评论