When we scroll chart, we want to keep the TRectangleTool stay at the old position.
It works well when scroll at one direction,
but when we change the scroll direction, it seems working strangely.
Code: Select all
__fastcall TForm7::TForm7(TComponent* Owner)
: TForm(Owner)
{
Series1->FillSampleValues(100);
ChartToolRect->Left = 100;
ChartToolRect->Width = 100;
ChartToolRect->Top = Chart1->MarginTop;
ChartToolRect->Height = Chart1->Height - Chart1->MarginTop - Chart1->MarginBottom;
ChartToolRect->AllowDrag = false;
ChartToolRect->AllowResize = false;
}
void __fastcall TForm7::Chart1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
float X, float Y)
{
if (Y > Chart1->Height * 1 / 2)
return;
// Move to the cusor position
ChartToolRect->Left = X;
// Remember the axes position of ChartToolRect
ChartToolRect->Tag = Chart1->BottomAxis->InternalCalcPosPoint(X);
}
void __fastcall TForm7::Chart1Scroll(TObject *Sender)
{
ChartToolRect->Left = Series1->CalcXPos(ChartToolRect->Tag);
}
Please find the attachment for example project.