全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:6872
推到 Plurk!
推到 Facebook!

請問BCB中的Chart使用上的2個問題!!

答題得分者是:RaynorPao
vk8051
一般會員


發表:22
回覆:33
積分:21
註冊:2007-08-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-09-10 14:42:47 IP:220.130.xxx.xxx 訂閱
Dear 前輩:
我最近在研究BCB中的CHART的這個元件,查了網站中其他的資料,現在也有辦法讓它動,但是出現2個不知道怎麼解決的問題.
我是使用一個TIMER去模擬一直有資料進來讓X軸會一直跑,然後用2個按紐去改變Y軸的資料,讓畫面看起來有一HI與LO的波型變化!!
問題一:
我已附上我的程式在下面,無毒放心,現在我的程式剛開始跑,我去改變Y軸的值波型都會上下跑,但是等到X軸的值一到最右邊或是跑一陣子後我在改變Y軸的值就幾乎不會在有上下的變動了,查了前文有提到要重設MIN/MAX值我有但是還是會不動作,請前輩給予指導.

問題二:
在CHART的畫面中左邊的Y座標有辦法設成正中間是0往上是1~100,往下是 -1 ~ -100,因為我在做一個數位的電壓顯示,所以一開機波型是在正中間0的位置,但是這個我試不出來,一直都是由下往上是0~100.

以上2個問題在麻煩前輩指導一下!!
謝謝!!



[code cpp]
void __fastcall TForm1::FormCreate(TObject *Sender)
{
y_tmp=50;
x_tmp=0;
Chart1->Title->Text->Clear();
Chart1->Title->Text->Add("電壓顯示");
Series1->AddXY(x_tmp,y_tmp,"",clBlue);
Chart1->BottomAxis->SetMinMax(0,1000);
Chart1->LeftAxis->SetMinMax(0,100);
Chart1->View3D=false; // 不要 3D 立體
Chart1->Legend->Visible=false; // 不秀圖例說明
}//這邊是一開始的設定

//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
// Tchart測試
if(x_tmp<65535)
{
x_tmp =5; //我用一個TIMER模擬有資料一直進來
}
else
{
x_tmp=0;
}
Series1->AddXY(x_tmp,y_tmp,"",clBlue);
Chart1->BottomAxis->Minimum = Chart1->BottomAxis->Maximum - 999;
Chart1->BottomAxis->SetMinMax(Chart1->BottomAxis->Minimum,Chart1->BottomAxis->Maximum);
Chart1->BottomAxis->Maximum = Chart1->BottomAxis->Maximum 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
y_tmp=50; //這是開始啟動的位置設定
x_tmp=1000;
Series1->AddXY(x_tmp,y_tmp,"",clBlue);
Chart1->BottomAxis->SetMinMax(0,1000);
Chart1->LeftAxis->SetMinMax(0,100);
Timer1->Enabled=1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if( y_tmp < 100 )
y_tmp =5; //在這邊改變Y軸的值模擬有資料變動讓波形有上下跑的情況
Label1->Caption = y_tmp;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
if( y_tmp > 0 )
y_tmp-=5; //在這邊改變Y軸的值模擬有資料變動讓波形有上下跑的情況
Label1->Caption = y_tmp;
}
[/code]
------
vincent
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-09-10 17:28:40 IP:210.208.xxx.xxx 訂閱
(1)原本的程式碼,因為 X 軸的移動速度,跟時間無法配合,因此到最後無法正確的顯示
(2)請參考以下的程式碼,看看可不可以? 然後再自行修改

[code cpp]
double x_tmp=0;
double y_tmp=0;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
y_tmp=0;
x_tmp=0;
Chart1->Title->Text->Clear();
Chart1->Title->Text->Add("電壓顯示");
Series1->AddXY(x_tmp, y_tmp, "", clBlue);
Chart1->BottomAxis->SetMinMax(0,10);
Chart1->LeftAxis->SetMinMax(-100,100);
Chart1->View3D=false; // 不要 3D 立體
Chart1->Legend->Visible=false; // 不秀圖例說明

Timer1->Enabled=false;
Timer1->Interval=100;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
y_tmp=0;
x_tmp=0;
Series1->AddXY(x_tmp, y_tmp, "", clBlue);
Chart1->BottomAxis->SetMinMax(0,10);
Chart1->LeftAxis->SetMinMax(-100,100);
Timer1->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if(y_tmp<100)
y_tmp =5;
Label1->Caption=y_tmp;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
if(y_tmp>-100)
y_tmp-=5;
Label1->Caption=y_tmp;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
// Tchart測試
if(x_tmp<65535)
{
x_tmp =(double)Timer1->Interval/1000;
}
else
{
x_tmp=0;
}
Series1->AddXY(x_tmp, y_tmp, "", clBlue);
if(x_tmp>=10)
{
Chart1->BottomAxis->Minimum =(double)Timer1->Interval/1000;
Chart1->BottomAxis->Maximum =(double)Timer1->Interval/1000;
Chart1->BottomAxis->SetMinMax(Chart1->BottomAxis->Minimum,Chart1->BottomAxis->Maximum);
}
}
//---------------------------------------------------------------------------
[/code]
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
編輯記錄
RaynorPao 重新編輯於 2008-09-10 17:34:29, 註解 無‧
vk8051
一般會員


發表:22
回覆:33
積分:21
註冊:2007-08-10

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-09-10 17:38:57 IP:220.130.xxx.xxx 訂閱
Orz~~~~~~~~~~~~
前輩可以了!!
我在自己比較一下2者差異與前輩提出我寫錯的地方~
謝謝~~

===================引 用 RaynorPao 文 章===================
(1)原本的程式碼,因為 X 軸的移動速度,跟時間無法配合,因此到最後無法正確的顯示
(2)請參考以下的程式碼,看看可不可以? 然後再自行修改

[code cpp]
double x_tmp=0;
double y_tmp=0;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
y_tmp=0;
x_tmp=0;
Chart1->Title->Text->Clear();
Chart1->Title->Text->Add("電壓顯示");
Series1->AddXY(x_tmp, y_tmp, "", clBlue);
Chart1->BottomAxis->SetMinMax(0,10);
Chart1->LeftAxis->SetMinMax(-100,100);
Chart1->View3D=false; // 不要 3D 立體
Chart1->Legend->Visible=false; // 不秀圖例說明

Timer1->Enabled=false;
Timer1->Interval=100;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
y_tmp=0;
x_tmp=0;
Series1->AddXY(x_tmp, y_tmp, "", clBlue);
Chart1->BottomAxis->SetMinMax(0,10);
Chart1->LeftAxis->SetMinMax(-100,100);
Timer1->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if(y_tmp<100)
y_tmp =5;
Label1->Caption=y_tmp;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
if(y_tmp>-100)
y_tmp-=5;
Label1->Caption=y_tmp;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
// Tchart測試
if(x_tmp<65535)
{
x_tmp =(double)Timer1->Interval/1000;
}
else
{
x_tmp=0;
}
Series1->AddXY(x_tmp, y_tmp, "", clBlue);
if(x_tmp>=10)
{
Chart1->BottomAxis->Minimum =(double)Timer1->Interval/1000;
Chart1->BottomAxis->Maximum =(double)Timer1->Interval/1000;
Chart1->BottomAxis->SetMinMax(Chart1->BottomAxis->Minimum,Chart1->BottomAxis->Maximum);
}
}
//---------------------------------------------------------------------------
[/code]
------
vincent
系統時間:2024-04-19 17:48:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!