Page 1 of 1

Problem in adding custom label in bottom axis

Posted: Fri Mar 26, 2010 2:12 pm
by 15654246
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

Re: Problem in adding custom label in bottom axis

Posted: Mon Mar 29, 2010 9:29 am
by 10050769
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,