Page 1 of 1

How to get the position of a custom axis

Posted: Wed Nov 21, 2007 8:25 am
by 9529132
Hi,

I added two custom axis to the chart and I would like to display the axis title at the top of each axis. here is how I did it.

m_chart1.GetAxis().AddCustom(FALSE);
m_chart1.GetAxis().AddCustom(FALSE);
m_chart1.GetAxis().GetCustom(0).SetPositionPercent(-7);
m_chart1.GetAxis().GetCustom(1).SetPositionPercent(-15);

Then in OnAfterDrawTchart1() I added

double x = m_chart1.GetAxis().GetLeft().GetPosition()-24;
double y = m_chart1.GetAxis().GetTop().GetPosition()-20;
m_chart1.GetCanvas().TextOut(x,y,"Axis-1");
x = m_chart1.GetAxis().GetCustom(0).GetPosition()-24;
m_chart1.GetCanvas().TextOut(x,y,"Axis-2");
x = m_chart1.GetAxis().GetCustom(1).GetPosition()-24;
m_chart1.GetCanvas().TextOut(x,y,"Axis-3");

However, all the text were overlapped. After I traced it, I found that the x value didn't change and was always the same as Left Axis position value. Would anyone please tell me how I should get the position value of the custom axis?

Thanks,
David

Posted: Wed Nov 21, 2007 9:19 am
by yeray
Hi David,

The following code achieves what you requested. In a few words, I recommend you to calculate all positions in pixels, not in percents to have better control.

In the other hand, please, use the property PositionPercent instead of Position to calculate the X position for the title because this property is not returning the correct value. This is a bug (TA05012598) we've added to the wish list to be fixed in further releases.


I hope the code in VB won't be a problem for you to understand what I'm doing.

Code: Select all

Private Sub Form_Load()
Dim i As Integer  
  TChart1.AddSeries scPoint
  TChart1.AddSeries scPoint

  For i = 0 To 25
    TChart1.Series(0).AddXY i, i * i, "", vbRed
    TChart1.Series(1).AddXY i, i Mod (i + 1), "", vbBlue
  Next i

  TChart1.Series(0).VerticalAxisCustom = TChart1.Axis.AddCustom(False)
  TChart1.Series(1).VerticalAxisCustom = TChart1.Axis.AddCustom(False)
  
  TChart1.Axis.Custom(0).PositionUnits = puPixels
  TChart1.Axis.Custom(1).PositionUnits = puPixels
    
  TChart1.Axis.Custom(0).PositionPercent = -20
  TChart1.Axis.Custom(1).PositionPercent = -60
  
  TChart1.Panel.MarginUnits = muPixels
  TChart1.Panel.MarginLeft = 100
  
  TChart1.Legend.Visible = False
End Sub

Private Sub TChart1_OnAfterDraw()
Dim x1, x2, y As Double
  x1 = TChart1.Axis.Custom(0).PositionPercent + TChart1.Panel.MarginLeft - 20
  x2 = TChart1.Axis.Custom(1).PositionPercent + TChart1.Panel.MarginLeft - 20
  y = TChart1.Axis.Top.Position - 20
  
  TChart1.Canvas.TextOut x1, y, "Axis-1"
  TChart1.Canvas.TextOut x2, y, "Axis-2"
End Sub

Posted: Wed Nov 21, 2007 9:57 am
by 9529132
It works now. Thanks!