Page 1 of 1

Get BottomAxis Value

Posted: Wed Mar 28, 2007 2:09 am
by 9243548
How can I get the BottomAxis Label for a given ColorLine->Value obtained in the ChartTool->DragLine() event?

thanks,
kev

Posted: Wed Mar 28, 2007 8:59 am
by yeray
Hello Kev,

the following example shows you two ways to achieve it:

Code: Select all

procedure TForm1.ChartTool1DragLine(Sender: TColorLineTool);
var x, y, index: Integer;
begin
  x:=Series1.CalcXPosValue(ChartTool1.Value);

//first way
  for y:=Chart1.Axes.Left.IStartPos to Chart1.Axes.Left.IEndPos do
       if Series1.Clicked(x,y)<>-1 then index:=Series1.Clicked(x,y);

//second way, more restrictive. Will only show the label when your dragline is placed exactly on a series point.
//  index:=Series1.XValues.Locate(ChartTool1.Value);

  if index<>-1 then
     Chart1.Title.Caption := Series1.Labels[index];
end;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Series1.Clear;

  for i:=0 to 10 do
    Series1.Add(Random,'label ' + IntToStr(i));
end;