Page 1 of 1

Drawing a label using DrawAxisLabel

Posted: Tue Jul 15, 2008 7:37 pm
by 14049416
Hi,

I have a a candle chart and I am trying to place a label just below the X axis lables whenever the date changes. I tried using the DrawAxisLabel method and had some success as first.

The problem is if I use the GetAxisDrawLabel event it only seems to fire when the label is ready to draw and by then it's too late. I also tried the GetAxisLabel but it seems to fire often and repeats values as if it is looping or something.

I need to be able to catch the date change of the candle first.

An example of what I am trying to do is this:

Code: Select all

  |	    |	    |	    |
  |	    |	    |	    |
23:15	23:45	00:15	00:45     
	         06/13
If you notice I want to display the date below the axis labels at any point where it changes, even if it is between the ticks.

Is this possible and how can I approach it?

Thanks,
Kevin

Posted: Wed Jul 16, 2008 9:36 am
by narcis
Hi Kevin,

Yes, you need to use the OnAfterDraw event for that. This works fine for me here:

Code: Select all

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var dt: TDateTime;
    str: String;
begin
  With Chart1.Axes.Bottom do
  begin
    dt:=Minimum;
    dt:=DateOf(dt);

    while dt<=Maximum do
    begin
      DateTimeToString(str, 'dd/mm', dt);
      DrawAxisLabel(CalcPosValue(dt), PosAxis + 20, 0, str);
      dt:=dt+1;
    end;
  end;
end;

Posted: Wed Jul 16, 2008 9:48 am
by narcis
Hi Kevin,

Sorry, I confused myself and posted a Delphi example using TeeChart VCL. This is the TeeChart for .NET equivalent:

Code: Select all

		void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
		{
			DateTime dt = DateTime.FromOADate(tChart1.Axes.Bottom.Minimum);
			dt = dt.Date.AddDays(1);

			while (dt <= DateTime.FromOADate(tChart1.Axes.Bottom.Maximum))
			{
				int x = tChart1.Axes.Bottom.CalcPosValue(dt.ToOADate());
				int y = tChart1.Axes.Bottom.Position + 20;
				String str = dt.Day.ToString() + "/" + dt.Month.ToString();
				Steema.TeeChart.Drawing.TextShape label = new Steema.TeeChart.Drawing.TextShape(tChart1.Chart);
				label.Transparent = true;

				tChart1.Axes.Bottom.DrawAxisLabel(x, y, 0, str, label);

				dt = dt.AddDays(1);
			}
		}

Posted: Wed Jul 16, 2008 1:52 pm
by 14049416
Absolutely perfect! Thanks NarcĂ­s.