Page 1 of 1

TMarksTipTool

Posted: Thu Jul 29, 2004 9:45 am
by 9231947
I want to display an alternative Series title when I mouse over the legend as well, can this control do it for me?

Any help will really be appreciated!



-Hendrik

Posted: Fri Jul 30, 2004 9:40 am
by Pep
Hi Hendrik,

yes, this can be done. Using the following code you can check when the mouse is over the Legend items, and also show a text. In this example will show the XValue of the Legend item.

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.FillSampleValues(10);
Chart1.View3D := False;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var tmp, tmpL : Integer;
begin
  With Chart1 do
  begin
    If (Series1.Clicked(X, Y) <> -1) And (OnSeriesPoint = False) Then
    begin
     Canvas.Brush.Style := bsSolid;
     Canvas.Pen.Color := clBlack;
     Canvas.Brush.Color := clWhite;
     canvas.TextOut(x+10,y,FormatFloat('#.00',Series1.XScreenToValue(x))+','+FormatFloat('#.00',Series1.YScreenToValue(y)));
     OnSeriesPoint := True;
    End;
    //Repaint Chart to clear Textoutputted Mark
    If (Series1.Clicked(X, Y) = -1) And (OnSeriesPoint = True) Then
    begin
      OnSeriesPoint := False;
      Repaint;
    End;

    tmpL := Chart1.Legend.Clicked(X, Y);
    If (tmpL <> -1) And ((tmpL <> tmpL2) Or (OnLegendPoint = False)) Then
    begin
       Repaint;
       Canvas.Brush.Color := Series1.LegendItemColor(tmpL);
       Canvas.Rectangle( X, Y, X + 20, Y + 20);
       Canvas.Brush.Color := clWhite;
       canvas.TextOut(x+7,y+7,FormatFloat('#.00',Series1.XValues.Items[Series1.LegendToValueIndex(tmpl)]));
       tmpL2 := tmpL;
       OnLegendPoint := True;
    End;

    If (Legend.Clicked(X, Y) = -1) And (OnLegendPoint = True) Then
    begin
       OnLegendPoint := False;
       Repaint;
    End;
  End;
end;