Problem in adding custom label in bottom axis

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Avijit
Newbie
Newbie
Posts: 72
Joined: Tue Sep 15, 2009 12:00 am

Problem in adding custom label in bottom axis

Post by Avijit » Fri Mar 26, 2010 2:12 pm

Hi,
I am having problem in adding custom labels in bottom axis.

Actuallly, i am following the below steps...

I am drawing my own grid line and the number of gridline is 3 always.
I want 3 labels to be shown just below each grid line and one label at the start.
One problem is how can is i am not able to draw the labels at these positions.
Another problem is, the first and the last label is always getting truncated because of the size.

Code: Select all

      public CreateControl()
      {
        mcCharControl.Axes.Bottom.Visible = true;
        mcCharControl.Axes.Bottom.Grid.Visible = false;
        mcCharControl.Axes.Bottom.Labels.Visible = true;
        mcCharControl.Axes.Bottom.Labels.Style = Steema.TeeChart.AxisLabelStyle.Value;
        mcCharControl.Axes.Bottom.Labels.TextAlign = StringAlignment.Near;
        mcCharControl.Axes.Bottom.Labels.Separation = 10;
        mcCharControl.Axes.Bottom.MinorGrid.Visible = false;
        mcCharControl.Axes.Bottom.MinorTicks.Visible = false;
        mcCharControl.Axes.Bottom.Labels.Font.Bold = true;
        mcCharControl.Axes.Bottom.Labels.ClipText = false;
        mcCharControl.Axes.Bottom.Labels.Font.Name = "Arial";
        mcCharControl.Axes.Bottom.Labels.Font.SizeFloat = 8.5f;
        mcCharControl.Axes.Left.Labels.Items.Clear();

        mcCharControl.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(mcCharControl_AfterDraw);
    }

      void mcCharControl_AfterDraw(object sender, Graphics3D g)
      {
        Steema.TeeChart.TChart chart = sender as Steema.TeeChart.TChart;
        //chart.Axes.Bottom.Increment = chart.Axes.Bottom.Maximum/3;


        chart.Axes.Bottom.Labels.Items.Clear();
        //Get the value at the specific location where grid line is drawn - Not getting these
        int _ColumnWidth = (int)(chart.Chart.ChartRect.Width) / 3;

        int YPosUnit = 0;
        for (int i = 0; i < 3; i++)
        {
          double Val = chart.Axes.Bottom.CalcPosPoint(YPosUnit);
          int StartPos = YPosUnit;
          (chart.Axes.Bottom.Labels.Items.Add(Val)).Font.Bold = true;
          YPosUnit = YPosUnit + _ColumnWidth;
        }

      }

      public void DrawGridLines(Rectangle ChartRect, Steema.TeeChart.Drawing.Graphics3D g)
      {
        int iHorLines = 3;
        int iVerLines = 3;

        double _ColumnWidth = (ChartRect.Width) / iVerLines;
        double _RowHeight = ((double)(ChartRect.Height) / (double)(iHorLines));


        //Draw vertical grid lines
        double YPosUnit = 0;
        for (int i = 0; i < iVerLines; i++)
        {
          double StartPos = YPosUnit;
          DrawVerticalTicks(g, _ColumnWidth, StartPos, ChartRect);
          YPosUnit = YPosUnit + _ColumnWidth;
          PaintGridLine(g, YPosUnit, (double)ChartRect.Bottom, YPosUnit, (double)ChartRect.Top);
        }


        //Draw the Horizontal grid lines
        double XPosUnit = 0;
        for (int i = 0; i < iHorLines; i++)
        {
          double StartPos = XPosUnit;
          DrawHorTicks(g, _RowHeight, StartPos, ChartRect);
          XPosUnit = XPosUnit + _RowHeight;
          PaintGridLine(g, (double)ChartRect.Left, XPosUnit, (double)ChartRect.Right, XPosUnit);
        }


      }



Please let me know if i am doing anything wrong.

Regards,
Avijit

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Problem in adding custom label in bottom axis

Post by Sandra » Mon Mar 29, 2010 9:29 am

Hello Avijit,

I think that you should customize that using the GetNextAxisLabel event as shown in the examples on those threads:

http://www.teechart.net/support/viewtopic.php?t=8392
http://www.teechart.net/support/viewtopic.php?t=4552

Hope this helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply