如何用滑鼠點選並移動 TChart 物件上的資料點? |
尚未結案
|
dondon923
一般會員 ![]() ![]() 發表:5 回覆:3 積分:1 註冊:2004-03-29 發送簡訊給我 |
|
dondon923
一般會員 ![]() ![]() 發表:5 回覆:3 積分:1 註冊:2004-03-29 發送簡訊給我 |
關於個人提出的這個問題,目前我的作法是利用 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 發送簡訊給我 |
關於個人提出的這個問題,目前我的作法是利用 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);
}
} 不知道大家是否還有更好的作法呢?
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |