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

如何用滑鼠點選並移動 TChart 物件上的資料點?

尚未結案
dondon923
一般會員


發表:5
回覆:3
積分:1
註冊:2004-03-29

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-04-13 10:47:58 IP:61.30.xxx.xxx 未訂閱
請問各位前輩,小弟想要寫一個程式,可以用 TChart 物件畫出五個資料點,並且用線段相連接,但是還需要可以用滑鼠點選並移動特定資料點的功能,是否有方法可以做到呢? 還是有其他的 VCL 元件可以提供類似的功能呢?    先謝謝大家 
dondon923
一般會員


發表:5
回覆:3
積分:1
註冊:2004-03-29

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-04-22 12:01:34 IP:61.30.xxx.xxx 未訂閱
關於個人提出的這個問題,目前我的作法是利用 TChart  的三個事件來達成的,分別是 OnMouseDown, OnMouseMove, OnMouseUp 另外,我還在TChart上另外增加了一個Shape物件,來只出示那個資料點 被選取了,作法如下:    在OnMouseDown的事件的程式大致如下:    void __fastcall TMainForm::chart1MouseDown(TObject *Sender,       TMouseButton Button, TShiftState Shift, int X, int Y) {     //檢查是否有chart1上的資料點被點選 INT Index = chart1->Series[0]->Clicked(X,Y); if( Index != -1 ) { PointIndex = Index; PointSelFlag = true; //以一個shape來指出那個資料點被選取了 Shape1->Top = Y - 4; Shape1->Left = X - 4; Shape1->Visible = true; } } 在 OnMouseMove 的事件處理如下 void __fastcall TMainForm::Chart1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { INT PosX = X, PosY = Y; if( PointSelFlag ) { //移動Shape1以達到資料點移動的效果 Shape1->Top = PosY - 4; Shape1->Left = PosX - 4; } } 在 OnMouseUp 的事件處理如下 void __fastcall TMainForm::Chart1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { float CurrX, CurrY; if( PointSelFlag ) { //計算出目前Shape1的位置在Chart1的資料座標值 CurrX = (float)((float)(Shape1->Left 4)/512) * StrToInt( labC4ADSRTime->Caption ); CurrY = 127 - (Shape1->Top 4); Shape1->Visible = false; PointSelFlag = false; //將原來選的那個資料點刪除 加上新資料點 Chart1->Series[0]->Delete(PointIndex); Chart1->Series[0]->AddXY((INT)CurrX, (INT)CurrY); } } 不知道大家是否還有更好的作法呢?
dondon923
一般會員


發表:5
回覆:3
積分:1
註冊:2004-03-29

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-04-22 12:01:48 IP:61.30.xxx.xxx 未訂閱
關於個人提出的這個問題,目前我的作法是利用 TChart  的三個事件來達成的,分別是 OnMouseDown, OnMouseMove, OnMouseUp 另外,我還在TChart上另外增加了一個Shape物件,來只出示那個資料點 被選取了,作法如下:    在OnMouseDown的事件的程式大致如下:    void __fastcall TMainForm::chart1MouseDown(TObject *Sender,       TMouseButton Button, TShiftState Shift, int X, int Y) {     //檢查是否有chart1上的資料點被點選 INT Index = chart1->Series[0]->Clicked(X,Y); if( Index != -1 ) { PointIndex = Index; PointSelFlag = true; //以一個shape來指出那個資料點被選取了 Shape1->Top = Y - 4; Shape1->Left = X - 4; Shape1->Visible = true; } } 在 OnMouseMove 的事件處理如下 void __fastcall TMainForm::Chart1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { INT PosX = X, PosY = Y; if( PointSelFlag ) { //移動Shape1以達到資料點移動的效果 Shape1->Top = PosY - 4; Shape1->Left = PosX - 4; } } 在 OnMouseUp 的事件處理如下 void __fastcall TMainForm::Chart1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { float CurrX, CurrY; if( PointSelFlag ) { //計算出目前Shape1的位置在Chart1的資料座標值 CurrX = (float)((float)(Shape1->Left 4)/512) * StrToInt( labC4ADSRTime->Caption ); CurrY = 127 - (Shape1->Top 4); Shape1->Visible = false; PointSelFlag = false; //將原來選的那個資料點刪除 加上新資料點 Chart1->Series[0]->Delete(PointIndex); Chart1->Series[0]->AddXY((INT)CurrX, (INT)CurrY); } } 不知道大家是否還有更好的作法呢?
系統時間:2024-07-06 22:58:09
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!