LabelSource (Formatting Problem)

TeeChart for ActiveX, COM and ASP
Post Reply
Craig
Newbie
Newbie
Posts: 1
Joined: Tue Jan 13, 2004 5:00 am

LabelSource (Formatting Problem)

Post by Craig » Mon Jan 19, 2004 10:06 pm

What I am doing is graphing data out of a very large ADO Recordset.
In this program you can graph multiple Y – Axis’s on the Left and Right Axis. The X-Axis (bottom) value is always based off of Date/Time but the labels for the X-Axis could be either Date/Time Based or Based off of another Fields value. I am currently setting the LabelSource property to another field besides time in the Recordset. The field in the Recordset is declared as a single but the value is formatted in the Database to only two decimal places. When I graph this out the Labels on the X-Axis have like 12 Decimal places and I can not format them down to two decimal places. If the Value in the Recordset /Database is a whole number but still declared as a single then the labels come out like they should with no decimal places.

By the way I even went into the database and manually formatted the channels to 2 decimal places before I loaded it into the chart and it still did the same thing. For some reason it does not like labels that are assigned as values with decimal places.

Here is some sample code



Left Axis

MainForm.TChart1.Axis.Bottom.Labels.Style = taltext ‘ Only if it is not Date/Time on X-Axis Labels


MainForm.TChart1.AddSeries (scFastLine)
With MainForm.TChart1.Series(SeriesCount - 1)
.DataSource = MainForm.AdodcDataViewer.Recordset
.Active = True
.VerticalAxis = aRightAxis
.DatasourceType = dstAllRecords
.asFastLine.DrawAllPoints = False
.ColorEachPoint = False
.XValues.Order = loNone
.YValues.Order = loNone

' check to see if it is time based or not
If StrComp(XAxisName, "TimeStamp", vbTextCompare) = 0 Then
.XValues.DateTime = True
Else
.XValues.DateTime = False
End If

.YValues.ValueSource = ChannelCollection(i).ChannelName (Field In Recrordset)
.XValues.ValueSource = "TimeStamp" ' (Field In Recordset)
.LabelsSource = XAxisName ' (Field in recordset not Date/Time)
end


Thanks for all of your help,

Craig MacLeod

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Wed Jan 21, 2004 11:06 am

Hi Craig,

You should be able to format bottom axis labels using the OnGetAxisLabel event as in the example below:

Code: Select all

Private Sub Form_Load()
Dim YValue As Single
With TChart1
    .AddSeries scLine
    For i = 0 To 10
        YValue = Rnd * 10
        .Series(0).AddXY i, YValue, YValue, clTeeColor
    Next i
End With
End Sub

Private Sub TChart1_OnGetAxisLabel(ByVal Axis As Long, ByVal SeriesIndex As Long, ByVal ValueIndex As Long, LabelText As String)
If Axis = atBottom Then
    LabelText = Round(LabelText, 2)
End If
End Sub
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Post Reply