Page 1 of 1

Custom Bottom Axis

Posted: Fri Feb 20, 2015 10:56 am
by 16071129
MS Chart.JPG
Custom Bottom Axis
MS Chart.JPG (69.38 KiB) Viewed 4734 times
How can we create Bottom Axis same as shown in above image?

Re: Custom Bottom Axis

Posted: Fri Feb 20, 2015 2:26 pm
by Christopher
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"));
        }
      }
    }