⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cfxrealtime.cpp

📁 Delphi Component - Chart Fx
💻 CPP
字号:
// CfxRealTime.cpp : implementation file
//

#include "stdafx.h"
#include "cfx98.h"
#include "CfxRealTime.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCfxRealTime dialog

int nOffset;


CCfxRealTime::CCfxRealTime(CWnd* pParent /*=NULL*/)
	: CDialog(CCfxRealTime::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCfxRealTime)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CCfxRealTime::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCfxRealTime)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP

	// ***CFX***
	// Do not use class wizard to generate these. It will cause the generation of unecesary classes
	DDX_Control(pDX, IDC_CHART1, m_ChartFX1);
	DDX_Control(pDX, IDC_CHART2, m_ChartFX2);
	if (!pDX->m_bSaveAndValidate) { // Link Chart FX pointer to control window
		m_pChartFX1 = m_ChartFX1.GetControlUnknown();
		m_pChartFX2 = m_ChartFX2.GetControlUnknown();
	}
	// ***CFX***

}


BEGIN_MESSAGE_MAP(CCfxRealTime, CDialog)
	//{{AFX_MSG_MAP(CCfxRealTime)
	ON_BN_CLICKED(IDC_ACQUIREDATA, OnAcquiredata)
	ON_BN_CLICKED(IDC_ADDONE, OnAddone)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCfxRealTime message handlers

BOOL CCfxRealTime::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	m_pChartFX1 = NULL;
	m_pChartFX2 = NULL;
	return CDialog::DestroyWindow();
}

void CCfxRealTime::OnAcquiredata() 
{
	// TODO: Add your control notification handler code here
    if (IsDlgButtonChecked(IDC_ACQUIREDATA))
		SetTimer(1,100,NULL);		// A 10th of a second
	else
		KillTimer(1);
	
}

void CCfxRealTime::OnAddone() 
{
	// TODO: Add your control notification handler code here
	// Switch realtime styles when the end of the
    if (nOffset == 20) {
        m_pChartFX1->RealTimeStyle = CRT_NOWAITARROW;
        m_pChartFX1->Refresh();
        m_pChartFX2->RealTimeStyle = CRT_NOWAITARROW;
        m_pChartFX2->Refresh();
        nOffset++;
    } else {
        if (nOffset < 20) 
            nOffset++;
 	}

    //insert one point from the left in realtime for each series
    m_pChartFX1->OpenDataEx((CfxCod) (COD_VALUES | COD_INSERTPOINTS), 2, 1);
    m_pChartFX1->ValueEx[0][0] = -50 + rand() % 100;
    m_pChartFX1->ValueEx[1][0] = -50 + rand() % 100;
    m_pChartFX1->CloseData((CfxCod) (COD_VALUES | COD_REALTIME));
    
    //add one point from the right in realtime for each series
    m_pChartFX2->OpenDataEx((CfxCod) (COD_VALUES | COD_ADDPOINTS), 2, 1);
    m_pChartFX2->ValueEx[0][0] = -50 + rand() % 100;
    m_pChartFX2->ValueEx[1][0] = -50 + rand() % 100;
    m_pChartFX2->CloseData((CfxCod) (COD_VALUES | COD_REALTIME));
    
	
}

void CCfxRealTime::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	OnAddone();

	CDialog::OnTimer(nIDEvent);
}

BOOL CCfxRealTime::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
    //set the max and min values of the y-axis
    m_pChartFX1->Axis->Item[AXIS_Y]->Max = 75;
    m_pChartFX1->Axis->Item[AXIS_Y]->Min = -75;
    
    m_pChartFX2->Axis->Item[AXIS_Y]->Max = 75;
    m_pChartFX2->Axis->Item[AXIS_Y]->Min = -75;
    
    //set and initialize the buffer of values for this real time chart
    m_pChartFX1->MaxValues = 20;
    m_pChartFX1->OpenDataEx(COD_VALUES, 2, 20);
    m_pChartFX1->CloseData(COD_VALUES);
    
    m_pChartFX2->MaxValues = 20;
    m_pChartFX2->OpenDataEx(COD_VALUES, 2, 20);
    m_pChartFX2->CloseData(COD_VALUES);
    
    //set the color for each series of the chart
    m_pChartFX1->OpenDataEx(COD_COLORS, 2, 0);
    m_pChartFX1->Series->Item[0]->Color = RGB(255, 128, 0);
    m_pChartFX1->Series->Item[1]->Color = RGB(0, 128, 255);
    m_pChartFX1->CloseData(COD_COLORS);

    m_pChartFX1->LineWidth = 2;
    m_pChartFX1->MarkerShape = MK_NONE;
    
    m_pChartFX2->OpenDataEx(COD_COLORS, 2, 0);
    m_pChartFX2->Series->Item[0]->Color = RGB(255, 128, 0);
    m_pChartFX2->Series->Item[1]->Color = RGB(0, 128, 255);
    m_pChartFX2->CloseData(COD_COLORS);

    // Optimize scrolling. These lines will make the chart scroll faster.
    m_pChartFX1->TypeMask = (CfxType) (m_pChartFX1->TypeMask | CT_EVENSPACING);
    m_pChartFX2->TypeMask = (CfxType) (m_pChartFX2->TypeMask | CT_EVENSPACING);
    
    nOffset = 0;
    m_pChartFX1->RealTimeStyle = (CfxRealTimeStyle) (CRT_LOOPPOS | CRT_NOWAITARROW);
    m_pChartFX2->RealTimeStyle = (CfxRealTimeStyle) (CRT_LOOPPOS | CRT_NOWAITARROW);
	
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -