Custom Bottom Axis

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Custom Bottom Axis

Post by Quant » Fri Feb 20, 2015 10:56 am

MS Chart.JPG
Custom Bottom Axis
MS Chart.JPG (69.38 KiB) Viewed 4705 times
How can we create Bottom Axis same as shown in above image?

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Custom Bottom Axis

Post by Christopher » Fri Feb 20, 2015 2:26 pm

Quant wrote: How can we create Bottom Axis same as shown in above image?
As an approximation, I think this might be a reasonable start:

Code: Select all

    Candle series = new Candle();

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      tChart1.Series.Add(series);
      series.FillSampleValues(100);

      tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd";
      tChart1.Axes.Bottom.Increment = Utils.GetDateTimeStep(DateTimeSteps.OneWeek);

      tChart1.Panel.MarginBottom = 30;
      tChart1.AfterDraw += tChart1_AfterDraw;
    }

    void tChart1_AfterDraw(object sender, Graphics3D g)
    {
      Axis bottom = tChart1.Axes.Bottom;

      Rectangle rect = Utils.FromLTRB(bottom.IStartPos, bottom.Position, bottom.IEndPos, bottom.Position + g.FontHeight * 2);

      g.Pen.Color = Color.Red;
      g.Brush.Visible = false;
      g.Rectangle(rect);

      DateTime minDate = DateTime.FromOADate(bottom.Minimum);
      DateTime maxDate = DateTime.FromOADate(bottom.Maximum);

      for (DateTime date = minDate; date.Date <= maxDate; date = date.AddDays(1))
      {
        if(date.Day == 1)
        {
          DateTime tmpDate = new DateTime(date.Year, date.Month, date.Day);
          int tmpX = bottom.CalcPosValue(tmpDate.ToOADate());
          int tmpY = rect.Bottom + rect.Height;
          g.VerticalLine(tmpX, rect.Top, tmpY);

          g.Font.Color = Color.Red;
          g.TextOut(tmpX, tmpY - g.FontHeight, tmpDate.ToString("MMMM"));
        }
      }
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply