📄 realtime.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "realtime.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ChartfxLib_TLB"
#pragma link "ExtCtrls"
#pragma link "OleCtrls"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//set and initialize the buffer of values for this real time chart
ChartFX1->MaxValues = 20;
ChartFX1->OpenDataEx(COD_VALUES | COD_REMOVE, 2, 20);
ChartFX1->CloseData(COD_VALUES);
ChartFX2->MaxValues = 20;
ChartFX2->OpenDataEx(COD_VALUES | COD_REMOVE, 2, 20);
ChartFX2->CloseData(COD_VALUES);
// Optimize scrolling. These lines will make the chart scroll faster.
ChartFX1->SendMsg(0,0,CT_EVENSPACING);
ChartFX2->SendMsg(0,0,CT_EVENSPACING);
nOffset = 0;
ChartFX1->RealTimeStyle = CRT_LOOPPOS | CRT_NOWAITARROW;
ChartFX2->RealTimeStyle = CRT_LOOPPOS | CRT_NOWAITARROW;
ChartFX2->TypeEx |= CTE_NOLEGINVALIDATE;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AddOnePoint()
{
CfxCod nCOD;
String s;
// Switch realtime styles when the end of the
if (nOffset == 20) {
ChartFX1->RealTimeStyle = CRT_NOWAITARROW;
ChartFX1->Refresh();
ChartFX2->RealTimeStyle = CRT_NOWAITARROW;
ChartFX2->Refresh();
}
nCOD = COD_VALUES | COD_REALTIME;
//insert one point from the left in realtime for each series
ChartFX1->OpenDataEx(COD_VALUES | COD_INSERTPOINTS, 2, 1);
ChartFX1->ValueEx[0][0] = -50 + rand()*100.0/RAND_MAX;
ChartFX1->ValueEx[1][0] = -50 + rand()*100.0/RAND_MAX;
ChartFX1->CloseData(nCOD);
// Scroll x-axis labels too
if (CheckBox2->Checked) {
nCOD = nCOD | COD_SCROLLLEGEND;
s = nOffset;
if (nOffset >= 20) { // Eliminate first (scroll) and add one at the end
ChartFX2->Legend[0] = NULL;
ChartFX2->Legend[19] = StringToOleStr(s);
} else
ChartFX2->Legend[nOffset] = StringToOleStr(s);
}
// add one point from the right in realtime for each series
ChartFX2->OpenDataEx(COD_VALUES | COD_ADDPOINTS, 2, 1);
ChartFX2->ValueEx[0][0] = -50 + rand()*100.0/RAND_MAX;
ChartFX2->ValueEx[1][0] = -50 + rand()*100.0/RAND_MAX;
ChartFX2->CloseData(nCOD);
// Next
nOffset++;
}
void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
Timer1->Enabled = CheckBox1->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AddOnePoint();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
AddOnePoint();
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -