Page 1 of 1

Add Text to Chart

Posted: Mon Feb 27, 2006 10:01 am
by 9239733
Dear Sir,
I wanted to add Text to my chart with help of Canvas. Now my Problem is, that my text shouldn't be fixed with pixels, it should be added to the Chart with x, y cordination of the X and Y Axis.
Is it possible?

Next Problem:
I add the text now onAfterDraw. But the text is only visible when zooming. How could I see text text all time?

Posted: Mon Feb 27, 2006 10:12 am
by narcis
Hello,

Yes, this is possible doing something like in this code:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues();
  Chart1.Draw;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var X,Y: Integer;
begin
  X:=Chart1.Axes.Bottom.CalcXPosValue(2);
  Y:=Chart1.Axes.Left.CalcYPosValue(100);
  Chart1.Canvas.TextOut(X,Y,'My Custom Text');
end;
Next Problem:
I add the text now onAfterDraw. But the text is only visible when zooming. How could I see text text all time?
This is because you need to force the chart being drawn before calling Draw method as done in the snippet above.