Problem getting bottom axis min/max/increment.

TeeChart for ActiveX, COM and ASP
Post Reply
TonyVSUK
Advanced
Posts: 163
Joined: Wed Mar 01, 2006 12:00 am

Problem getting bottom axis min/max/increment.

Post by TonyVSUK » Thu Sep 30, 2010 9:07 am

Hello all,

I want to define a custom x axis as soon as a plot is created. But when I try and get the xMin, xMax and increment, all are returned as zero.

For example, the following code does not work (xmin,xmax and increment all come back from TChart as zero).

Code: Select all

Private Sub Command3_Click()

    TChart1.AddSeries scGantt
    TChart1.AddSeries scGantt
    TChart1.Aspect.View3D = False

  ' Disable automatic sorting by date
  TChart1.Series(0).XValues.Order = loNone
  TChart1.Series(1).XValues.Order = loNone

  ' Fill Gantt with sample date-time values:
  With TChart1.Series(0)
    .asGantt.AddGantt DateSerial(2002, 4, 1), DateSerial(2002, 4, 10), 0, "Series 1 - A"
    .asGantt.AddGantt DateSerial(2002, 4, 5), DateSerial(2002, 4, 15), 1, "Series 1 - B"

    ' Make marks visible
    .Marks.Visible = True
    .Marks.ShadowSize = 0
    .Marks.Gradient.Visible = True
    End With
  With TChart1.Series(1)
    .asGantt.AddGantt DateSerial(2002, 5, 2), DateSerial(2002, 5, 8), 2, "Series 2 - C"
    .asGantt.AddGantt DateSerial(2002, 5, 9), DateSerial(2002, 5, 21), 3, "Series 2 - D"

    .asGantt.Pointer.VerticalSize = 20
    ' Make marks visible
    .Marks.Visible = True
    .Marks.ShadowSize = 0
    .Marks.Gradient.Visible = True
    End With


   Dim nNumLablels As Long

Dim nMin As Double
Dim nMax As Double
Dim nIncrement As Double
Dim strTempString As String
Dim i As Double
Dim nLabelCount As Long

nMin = TChart1.Axis.Bottom.Minimum
nMax = TChart1.Axis.Bottom.Maximum
nIncrement = TChart1.Axis.Bottom.Increment
If nIncrement = 0 Then
    nIncrement = 1
End If

For i = nMin To nMax Step nIncrement
    strTempString = "QTest + " & i
    TChart1.Axis.Bottom.Labels.Add i, strTempString
Next i

nLabelCount = TChart1.Axis.Bottom.Labels.Count

End Sub

But if I separate the code into two subs both behind buttons and click each button in turn, it works.

Code: Select all

Private Sub Command3_Click()

    TChart1.AddSeries scGantt
    TChart1.AddSeries scGantt
    TChart1.Aspect.View3D = False

  ' Disable automatic sorting by date
  TChart1.Series(0).XValues.Order = loNone
  TChart1.Series(1).XValues.Order = loNone

  ' Fill Gantt with sample date-time values:
  With TChart1.Series(0)
    .asGantt.AddGantt DateSerial(2002, 4, 1), DateSerial(2002, 4, 10), 0, "Series 1 - A"
    .asGantt.AddGantt DateSerial(2002, 4, 5), DateSerial(2002, 4, 15), 1, "Series 1 - B"

    ' Make marks visible
    .Marks.Visible = True
    .Marks.ShadowSize = 0
    .Marks.Gradient.Visible = True
    End With
  With TChart1.Series(1)
    .asGantt.AddGantt DateSerial(2002, 5, 2), DateSerial(2002, 5, 8), 2, "Series 2 - C"
    .asGantt.AddGantt DateSerial(2002, 5, 9), DateSerial(2002, 5, 21), 3, "Series 2 - D"

    .asGantt.Pointer.VerticalSize = 20
    ' Make marks visible
    .Marks.Visible = True
    .Marks.ShadowSize = 0
    .Marks.Gradient.Visible = True
    End With
    Dim nNumLablels As Long

End Sub




Private Sub Command4_Click()
Dim nNumLablels As Long
Dim nMin As Double
Dim nMax As Double
Dim nIncrement As Double
Dim strTempString As String
Dim i As Double
Dim nLabelCount As Long

nMin = TChart1.Axis.Bottom.Minimum
nMax = TChart1.Axis.Bottom.Maximum
nIncrement = TChart1.Axis.Bottom.Increment
If nIncrement = 0 Then
    nIncrement = 1
End If

For i = nMin To nMax Step nIncrement
    strTempString = "QTest + " & i
    TChart1.Axis.Bottom.Labels.Add i, strTempString
Next i

nLabelCount = TChart1.Axis.Bottom.Labels.Count

End Sub
How can I get the values from the axis?

Tony.

TonyVSUK
Advanced
Posts: 163
Joined: Wed Mar 01, 2006 12:00 am

Re: Problem getting bottom axis min/max/increment.

Post by TonyVSUK » Thu Sep 30, 2010 9:37 am

The same thing happens with GetChartRect. It returns 0,0,0,0.

CTeeRect ChartRect = pTChart->GetChartRect();

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

Re: Problem getting bottom axis min/max/increment.

Post by Sandra » Thu Sep 30, 2010 3:17 pm

Hello Tony,
For example, the following code does not work (xmin,xmax and increment all come back from TChart as zero).
I think that you need use MinXValue and MaxXValue axes property for get Minimum or Maximum of Bottom Axes as do in next lines of code:

Code: Select all

nMin = TChart1.Axis.Bottom.MinXValue()
nMax = TChart1.Axis.Bottom.MaxXValue()
The same thing happens with GetChartRect. It returns 0,0,0,0.

CTeeRect ChartRect = pTChart->GetChartRect();
If you would use ChartRect you need calculate Left, Top, Right, Bottom parameters as explain example there are in help reference, concretely reference ChartRect

I hope will 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

TonyVSUK
Advanced
Posts: 163
Joined: Wed Mar 01, 2006 12:00 am

Re: Problem getting bottom axis min/max/increment.

Post by TonyVSUK » Thu Sep 30, 2010 3:23 pm

Code: Select all

nMin = TChart1.Axis.Bottom.MinXValue()
nMax = TChart1.Axis.Bottom.MaxXValue()
This works, thanks.
If you would use ChartRect you need calculate Left, Top, Right, Bottom parameters as explain example there are in help reference, concretely reference ChartRect
I don't understand what you mean here. When I call TChart1.ChartRect(), all four elements (top, bottom, left and right) are zero. It should return the size of the plot area.

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

Re: Problem getting bottom axis min/max/increment.

Post by Sandra » Mon Oct 04, 2010 9:25 am

Hello TonyVSUK,
I don't understand what you mean here. When I call TChart1.ChartRect(), all four elements (top, bottom, left and right) are zero. It should return the size of the plot area.
Sorry for delay. The ChartRect function sets the Axis bounding rectangle adding the 3D percent offset in pixels to the Right and Top coordinates. It should be used before painting the Chart component to which you wish it to apply as do in next example:

Code: Select all

Private Sub Form_Load()
  With TChart1
    .Aspect.View3D = False
    .Legend.Visible = False
    .Aspect.ApplyZOrder = False
    'Pie 0
    .AddSeries scPie
    .Series(0).FillSampleValues 3
    'Pie 1
    .AddSeries scPie
    .Series(1).FillSampleValues 7
    'Pie 2
    .AddSeries scPie
    .Series(2).FillSampleValues 5

    'Pie 3
    .AddSeries scPie
    .Series(0).FillSampleValues 6
    End With
End Sub

Private Sub TChart1_OnSeriesBeforeDrawValues(ByVal SeriesIndex As Long)

 With TChart1
   Select Case SeriesIndex
    Case 0: .ChartRect 0, 0, _
                       .Canvas.Width / 2, .Canvas.Height / 2
    Case 1: .ChartRect .Canvas.Width / 2, 0, _
                       .Canvas.Width, .Canvas.Height / 2
    Case 2: .ChartRect 0, .Canvas.Height / 2, _
                       .Canvas.Width / 2, .Canvas.Height

    Case 3: .ChartRect .Canvas.Width / 2, .Canvas.Height / 2, _
                       .Canvas.Width, .Canvas.Height
   End Select
 End With
End Sub
Also, if you want bounding rectangle can be obtained via Axis Positions as next lines of code:

Code: Select all

TChart.Axis.Left.Position, 
TChart.Axis.Top.Position - TChart.Aspect.Height3D, 
TChart.Axis.Right.Position + TChart.Aspect.Width3D, 
TChart.Axis.Bottom.Position
I hope will 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

TonyVSUK
Advanced
Posts: 163
Joined: Wed Mar 01, 2006 12:00 am

Re: Problem getting bottom axis min/max/increment.

Post by TonyVSUK » Mon Oct 04, 2010 11:45 am

Code: Select all

TChart.Axis.Left.Position,
TChart.Axis.Top.Position - TChart.Aspect.Height3D,
TChart.Axis.Right.Position + TChart.Aspect.Width3D,
TChart.Axis.Bottom.Position
I don't really understand what this gives me. The values do not correspond with the plot area (which is what I am after). I don't want to change the plot area, I just want to know the height so that I can make my gantt bars the correct size.

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

Re: Problem getting bottom axis min/max/increment.

Post by Sandra » Mon Oct 04, 2010 3:25 pm

Hello TonyVSUK,

I have made a simple example, where calculated ChartRect values, using TChart1.Axies.Left/Bottom/Top/Right.Postion and return are correct values of ChartRect. Could you please, check if next code works as you want and solve your problem?

Code: Select all

Private Sub Form_Load()
InitializeChart
End Sub
Private Sub InitializeChart()
 TChart1.AddSeries scBar
 TChart1.Series(0).FillSampleValues (6)
 TChart1.Environment.InternalRepaint
 Dim r As TeeChart.TeeRect
    r.Left = TChart1.Axis.Left.Position
    r.Top = TChart1.Axis.Top.Position
    r.Right = TChart1.Axis.Right.Position
    r.Bottom = TChart1.Axis.Bottom.Position
    height = r.Bottom-r.top
End Sub
I hope will 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

TonyVSUK
Advanced
Posts: 163
Joined: Wed Mar 01, 2006 12:00 am

Re: Problem getting bottom axis min/max/increment.

Post by TonyVSUK » Wed Oct 06, 2010 9:50 am

Code: Select all

Dim r As TeeChart.TeeRect
    r.Left = TChart1.Axis.Left.Position
    r.Top = TChart1.Axis.Top.Position
    r.Right = TChart1.Axis.Right.Position
    r.Bottom = TChart1.Axis.Bottom.Position
As I said earlier, this does not return the correct values, even in your example.
"Bottom" is correct
"Left" is correct
"Top" is incorrect
"Right" is incorrect

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Problem getting bottom axis min/max/increment.

Post by Narcís » Wed Oct 06, 2010 1:43 pm

Hi Tony,
How can I get the values from the axis?
The problem here is that since the chart has not been painted yet those properties have not been calculated yet. You need the chart to be painted before retrieving them, for example:

Code: Select all

    TChart1.Environment.InternalRepaint
    
    nMin = TChart1.Axis.Bottom.Minimum
    nMax = TChart1.Axis.Bottom.Maximum
    nIncrement = TChart1.Axis.Bottom.Increment
That's why separating the code in 2 buttons worked fine. Noticed that Increment=0 means it's automatic.
The same thing happens with GetChartRect. It returns 0,0,0,0.

CTeeRect ChartRect = pTChart->GetChartRect();
Same applies here, you should also call InternalRepaint. You can use Sandra's last example with little changes. Since by default Top and Right axes are not visible you should calculate ChartRect from Left and Bottom axes positions:

Code: Select all

Private Sub Form_Load()
    TChart1.AddSeries scBar
    TChart1.Series(0).FillSampleValues (6)
    
    TChart1.Environment.InternalRepaint
    
    Dim r As TeeChart.TeeRect
    
    r.Left = TChart1.Axis.Bottom.IStartPos
    r.Top = TChart1.Axis.Left.IStartPos
    r.Right = TChart1.Axis.Bottom.IEndPos
    r.Bottom = TChart1.Axis.Left.IEndPos
    
    ChartHeight = r.Bottom - r.Top
    TChart1.Header.Text(0) = "ChartRect height is " & CStr(ChartHeight)
End Sub
Hope this helps!
Best Regards,
Narcís Calvet / 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

TonyVSUK
Advanced
Posts: 163
Joined: Wed Mar 01, 2006 12:00 am

Re: Problem getting bottom axis min/max/increment.

Post by TonyVSUK » Wed Oct 06, 2010 2:12 pm

Does "InternalRepaint" actually paint the graph on the screen?

I want to avoid painting once just to calculate the plot area, and then again once I've worked out the gantt bar sizes. Having to paint twice will just introduce lots of flicker.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Problem getting bottom axis min/max/increment.

Post by Narcís » Wed Oct 06, 2010 2:21 pm

Hi Tony,

No, InternalRepaint forces the internal bitmap used to render the chart to be painted.
Best Regards,
Narcís Calvet / 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

TonyVSUK
Advanced
Posts: 163
Joined: Wed Mar 01, 2006 12:00 am

Re: Problem getting bottom axis min/max/increment.

Post by TonyVSUK » Wed Oct 06, 2010 5:22 pm

Thanks, that seems to have done the job.

Tony.

Post Reply