VS2019 MFC Teechart V5.1曲线控件使用方法Teechart Activex V5.1控件绘图控件 动态绘图

35 篇文章 5 订阅

Teechart控件安装注册:

        1. 将TeeChart5.ocx 复制到C:\Windows\SysWOW64。
        2. 找到同目录下的cmd.exe。
        3. 右键 管理员身份 打开 ,此刻进入的是system32 (不是管理员打开cmd的话,用win + R的话,会提示模块已加载,但对DllRegisterServer的调用失败)。
        4. 使用cd命令,进入 64位的目录 cd C:WindowsSysWOW64。
        5. 执行 regsvr32 TeeChart5.ocx 系统会提示成功。

 Teechart控件源文件:

        VS2019通过MFC Typelib类向导添加Teechart相关类后会发生一些意想不到的错误,例如类型确实,文件缺失等错误。解决办法就是不适用MFC TypeLib添加Teechart的相关类。通过手动添加的方式来添加相关类文件。

 Teechart动态用法:

        下面主要介绍动态添加曲线、改变曲线颜色、设置曲线外观、改变曲线类型、改变面板颜色、面板样式等相关的功能,导入导出功能。

1、 Teechart添加曲线:

        手动添加相关类,添加相关类的头文件。在添加类的头文件种增加如下语句,编译报错的都增加相关的重命名代码。

#import "C:\\WINDOWS\\SysWow64\\TeeChart5.ocx" no_namespace rename("LoadImage","myLoadImage") rename("TextOut", "myTextOut")

        #include"CSeries.h"
        #include"MacroDefinition.h"
        #include"CTCHART_CURVE.h"
        #include"CAxes.h"
        #include"CAxis.h"
        #include"CGradient.h"
        #include"CPanel.h"
        #include"CLegendSymbol.h"
        #include"CAspect.h"
        #include"CChartGrid.h"
        #include"CPen.h"
        #include"CJPEGExport.h"
        #include"CBMPExport.h"
        #include"CExport.h"
        #include"CLineSeries.h"
        #include"CFastLineSeries.h"
        #include"CImport.h"
        #include"CPrinter.h"

变量定义

        定义一个Teechart图标控件类型变量和3个曲线类变量

        CTCHART_CURVE m_TemCurve;

       CSeries       m_TemZoneChannelOne, m_TemZoneChannelTwo, m_TemZoneChannelThree;   

在timer种自动添加曲线 

void CTemCurveControl::OnTimer(UINT_PTR nIDEvent)
{
	switch (nIDEvent)
	{
	case 1:
	{
		CString str;
		m_TemZoneChannelOne   = (CSeries)m_TemCurve.Series(0);
		m_TemZoneChannelTwo   = (CSeries)m_TemCurve.Series(1);
		m_TemZoneChannelThree = (CSeries)m_TemCurve.Series(2);
		double y = 0;

		data++;
		m_TemZoneChannelOne.AddXY(double(data) / 60, sin(double(data) / 5), NULL, 0);//A为横坐标 Z1为纵坐标画连线、
		m_TemZoneChannelTwo.AddXY(double(data) / 50, cos(double(data) / 50), NULL, 0);//A为横坐标 Z1为纵坐标画连线
		m_TemZoneChannelThree.AddXY(double(data) / 60, cos(double(data) / 5), NULL, 0);//A为横坐标 Z1为纵坐标画连线
		break;
	}
	default:
		break;
	}
	CDialogEx::OnTimer(nIDEvent);
}

 2、改变曲线颜色(简单封装)

void CTemCurveControl::OnSetSeriesColor(CSeries mCeries,COLORREF mColor)
{
	mCeries.put_Color(mColor);
}

 3、改变轴的范围(简单封装)

void CTemCurveControl::OnSetAxisMinAndMaxValue(CTCHART_CURVE& mTeechar, double Xmini, double Xmax, double Ymin, double Ymax)
{
	CAxes    m_Axis= mTeechar.get_Axis();
	CAxis    m_BottomXAxis = m_Axis.get_Bottom();
	CAxis    m_LeftYAxis = m_Axis.get_Left();
	m_BottomXAxis.SetMinMax(Xmini, Xmax);
	m_LeftYAxis.SetMinMax(Ymin, Ymax);
	m_BottomXAxis.Scroll(1.0,TRUE);
	
	m_BottomXAxis.put_GridCentered(TRUE);
}

4、启用面板渐变(简单封装)

void CTemCurveControl::OnEnablePanelGradientVisible(CTCHART_CURVE& mTeechar,BOOL mVisible)
{
	CPanel   m_Panel = mTeechar.get_Panel();
	CGradient m_Gradiet = m_Panel.GetGradient();
	m_Gradiet.SetVisible(mVisible);
}

 5、改变渐变颜色(简单封装)

void CTemCurveControl::OnSetTeechartPanelGadientVisible(CTCHART_CURVE& mTeechar,COLORREF mStartColor, COLORREF mEndColor/*,BOOL Visible*/)
{
	CPanel   m_Panel = mTeechar.get_Panel();
	CGradient m_Gradiet = m_Panel.GetGradient();
	m_Gradiet.SetStartColor(mStartColor);
	m_Gradiet.SetEndColor(mEndColor);
	

}

6、启用3D外观(简单封装)

void CTemCurveControl::OnSetTeechartAspect3DViewVisible(CTCHART_CURVE& mTeechar,BOOL IsView3D)
{
	CAspect Asp = mTeechar.get_Aspect();
	Asp.put_View3D(IsView3D);
}

 7、改变线型(简单封装)

void CTemCurveControl::OnCbnSelchangeComboLinestyleSelect()
{
	int m_LineStyleSel = 0;
	m_LineStyleSel = m_LineStyleSelectSet.GetCurSel();
	switch (m_LineStyleSel)
	{
	case 0:
		m_FastLineStyle = psSolid;
		break;
	case 1:
		m_FastLineStyle = psDash;
		break;
	case 2:
		m_FastLineStyle = psDot;
		break;
	case 3:
		m_FastLineStyle = psDashDot;
		break;
	case 4:
		m_FastLineStyle = psDashDotDot;
		break;
	case 5:
		m_FastLineStyle = psInsideFrame;
		break;
	case 6:
		m_FastLineStyle = psSmallDots;
		break;
	default:
		break;
	}
	for (int i = 0; i < m_TemCurve.get_SeriesCount(); i++)
	{
		OnSetSeriesStype(m_TemCurve, i, m_FastLineStyle);
		printf("OnSetSeriesStype(m_TemCurve, %d, %d)\n",i, m_FastLineStyle);
	}
}
void CTemCurveControl::OnSetSeriesStype(CTCHART_CURVE &mTchart, long CeriesIndex, long mStype)
{
	CSeries mSeries = mTchart.Series(CeriesIndex);
	CFastLineSeries mLines= mSeries.get_asFastLine();
	CPen1 mPen = mLines.get_LinePen();
	mPen.SetStyle(mStype);
}

 8、改变线宽(简单封装)

void CTemCurveControl::OnCbnSelchangeComboLinewithSelect()
{
	int m_LineWithSel = 0;
	m_LineWithSel = m_LineWithSelectSet.GetCurSel();
	switch (m_LineWithSel)
	{
	case 0:
		m_FastLineWith = 1;
		break;
	case 1:
		m_FastLineWith = 2;
		break;
	case 2:
		m_FastLineWith = 3;
		break;
	case 3:
		m_FastLineWith = 4;
		break;
	case 4:
		m_FastLineWith = 5;
		break;
	default:
		break;
	}
	for (int i = 0; i < m_TemCurve.get_SeriesCount(); i++)
	{
		OnSetSeriesLineWith(m_TemCurve, i, m_FastLineWith);
		printf("OnSetSeriesLineWith(m_TemCurve, %d, %d)\n",i, m_FastLineWith);
	}
}
void CTemCurveControl::OnSetSeriesLineWith(CTCHART_CURVE& mTchart, long CeriesIndex, long mLineWith)
{
	CSeries mSeries = mTchart.Series(CeriesIndex);
	CFastLineSeries mLines = mSeries.get_asFastLine();
	CPen1 mPen = mLines.get_LinePen();
	mPen.SetWidth(mLineWith);

}

  9、清除曲线(简单封装)

void CTemCurveControl::OnClearAllSeries(CTCHART_CURVE& mTchart)
{
	for (int i = 0; i < mTchart.get_SeriesCount(); i++)
	{
		((CSeries)(mTchart.Series(i))).Clear();
	}
}

10、面板颜色设置(简单封装) 

void CTemCurveControl::OnSetTeeChartPanelBackGroudColor(CTCHART_CURVE& mTeechar, COLORREF mPanelBkColor)
{
	CPanel   m_Panel = mTeechar.get_Panel();
	m_Panel.SetColor(mPanelBkColor);
}

 11、网格颜色设置(简单封装) 

void CTemCurveControl::OnSetTeechartAxisGridePenColor(CTCHART_CURVE& mTeechar, COLORREF Xaxis, COLORREF Yaxis)
{
	CAxes    m_Axis = mTeechar.get_Axis();
	CAxis    m_BottomXAxis = m_Axis.get_Bottom();
	CAxis    m_LeftYAxis = m_Axis.get_Left();
	CPen1	 mGridePendLeft   = m_LeftYAxis.get_GridPen();
	CPen1	 mGridePendBotton = m_BottomXAxis.get_GridPen();
	mGridePendLeft.SetColor(Xaxis);
	mGridePendBotton.SetColor(Yaxis);
}

  12、保存曲线(简单封装)

void CTemCurveControl::OnBnClickedButtonSaveTeechart()
{

	CString CFilePathName;
	CString mJpg, mTee, mBmp,mpdf;

	TCHAR szFilter[] = _T("JPG图片文件(.JPG)|*.JPG|文本文件(.txt)|*.txt|配置文件(.ini)|*.ini|word文件(.doc)|*.doc|曲线文件(.tee)|*.tee|位图文件(.bmp)|*.bmp|所有文件(*.*)|*.*||");
	CFileDialog dlg(FALSE, _T(""),_T("ReflowerTempretureCurve"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this,0, TRUE);

	CExport mSave = m_TemCurve.get_Export();
	if (dlg.DoModal() == IDCANCEL)
	{
		MessageBox(_T("保存文件已取消!"), _T("信息提示!"), MB_OK | MB_OKCANCEL | MB_ICONINFORMATION);
		return;
	}
	else 
	{
		switch (dlg.m_ofn.nFilterIndex)
		{
		case 1:
			CFilePathName = dlg.m_ofn.lpstrFile;
			CFilePathName = CFilePathName + dlg.m_ofn.lpstrDefExt;

			mSave.get_asJPEG();
			mSave.SaveToJPEGFile(CFilePathName, jpegBestQuality, 0, 100, 1023, 643);
			break;
		case 5:
			CFilePathName = dlg.m_ofn.lpstrFile;
			CFilePathName = CFilePathName + dlg.m_ofn.lpstrDefExt;

			mSave.SaveToFile(CFilePathName);
			break;
		case 6:
			CFilePathName = dlg.m_ofn.lpstrFile;
			CFilePathName = CFilePathName + dlg.m_ofn.lpstrDefExt;

			mSave.get_asBMP();
			mSave.SaveToBitmapFile(CFilePathName);
			break;
		case 7:
			CFilePathName = dlg.m_ofn.lpstrFile;
			CFilePathName.TrimRight(_T(".JPG"));
			CFilePathName = CFilePathName + dlg.m_ofn.lpstrDefExt;

		    mJpg = CFilePathName + _T(".JPG");
			mSave.get_asJPEG();
			mSave.SaveToJPEGFile(mJpg, jpegBestQuality, 0, 100, 1023, 643);

			mTee = CFilePathName + _T(".tee");
			mSave.SaveToFile(mTee);

			mBmp = CFilePathName + _T(".bmp");
			mSave.get_asBMP();
			mSave.SaveToBitmapFile(mBmp);

			//mSave.GetAsPDF();
			/*mpdf= CFilePathName + _T(".pdf");
			mExportPdf.SaveToFile(CFilePathName);*/
			break;
		default:
			break;
		}

	}
	/*GetSaveFileName(&dlg.m_ofn);
	dlg.GetFileExt();*/

	MessageBox(_T("温度曲线已保存到:") + CFilePathName + _T("目录下!"), _T("信息提示:"), MB_OK | MB_ICONINFORMATION);

}

   13、导入曲线(简单封装)//5.1导入导出PDF好像有问题,目前没有解决。

void CTemCurveControl::OnBnClickedButtonOpenTeechartFile()
{
	TCHAR szFilter[] = _T("曲线文件(.tee)|*.tee|文本文件(*.txt)|*.txt|所有文件(*.*|*.*||");
	CFileDialog fileDlg(TRUE, _T(""), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this, 0, TRUE);
	CString strFilePath;
	if (IDOK == fileDlg.DoModal())
	{
		strFilePath = fileDlg.GetPathName();
		CImport mImfile = static_cast<CImport> (m_TemCurve.get_Import());
		if (strFilePath!=_T(""))
		{
			mImfile.LoadFromFile(strFilePath);
		}
		else
		{
			printf("strFilePath = fileDlg.GetPathName(),获取文件名为空!\n");
			MessageBox(_T("要导入的文件为空,请选择曲线文件后再试!:"), _T("信息提示:"), MB_OK | MB_ICONINFORMATION);
			return;
		}
	}
}

曲线导出功能,曲线导出可导出为BMP文件、JPG文件以及.tee文件。保存时选择所有类型能同时保存3种格式的文件。 

 

 

 曲线文件导入,Teechart的曲线文件名后缀为.tee。

 

Teechart的曲线控件功能非常强大,此处不做过多详细的说明,只是告诉大家动态设置的一些方法,其他功能自己慢慢摸索即可。

  • 6
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值