Jump to content
Software FX Community

Additional labels X-Axis on log chart.


User (Legacy)
 Share

Recommended Posts

Hi everybody,

I'm using VB6 (SP5) with Chart FX 98 Client Server (5.0.4.0). The following

VB code produces the chart shown in form1.jpg. Which is almost what I want.

How can I also add labels to the X-Axis for 3 (first value), 30 and 300

(last value)? I tried (almost) everything, but I didn't succeed.

Any help would be appreciated.

Best regards, Arnoud

---------------------------------------------------------------

Option Explicit

Private Sub Form_Load()

Dim x(14) As Double, y(14) As Double

Dim xAxis, yAxis As Variant

Dim j As Integer

x(0) = 0.063

x(1) = 0.09

x(2) = 0.125

x(3) = 0.18

x(4) = 0.25

x(5) = 0.355

x(6) = 0.5

x(7) = 0.71

x(8) = 1#

x(9) = 2#

x(10) = 2.8

x(11) = 4#

x(12) = 6#

x(13) = 8#

y(0) = 6.91657866948258

y(1) = 11.1404435058078

y(2) = 17.3178458289335

y(3) = 27.9831045406547

y(4) = 40.8130939809926

y(5) = 55.596620908131

y(6) = 69.5881731784583

y(7) = 79.7782470960929

y(8) = 85.6388595564942

y(9) = 93.3474128827878

y(10) = 96.3569165786695

y(11) = 98.3104540654699

y(12) = 100#

y(13) = 100#

Set xAxis = ChartFX1.Axis(AXIS_X)

Set yAxis = ChartFX1.Axis(AXIS_Y)

ChartFX1.OpenDataEx COD_VALUES, 1, 14

ChartFX1.OpenDataEx COD_XVALUES, 1, 14

For j = 0 To 13

ChartFX1.ValueEx(0, j) = y(j)

ChartFX1.XValueEx(0, j) = x(j) * 100

Next j

ChartFX1.CloseData COD_XVALUES

ChartFX1.CloseData COD_VALUES

xAxis.LogBase = 10

xAxis.Min = 3

xAxis.Max = 300

xAxis.STEP = 1

End Sub

Link to comment
Share on other sites

Thanks for your help!

It took me some time to figure out how it works, but now I think I know. The

code below is what I could come up with.

But why does the line ".ValueToPixel dblValue, .Adm(CSA_MIN), dx, dy,

AXIS_Y" in the "AddChartLabel" procedure return a incorrect "dx" and "dy"

every first time I call the procedure? So in this case the "AddChartLabel 3"

will place the number at an incorrect spot (see attachement Form1.jpg),

while the rest looks fine. It doesn't matter if I first call the

"AddChartLabel 30", while the the 30 will be at the place the "3" is in this

example.

Hopefully you can tell me what I did wrong.

Thanks, Arnoud

--------------------------------------------------------------------------

Option Explicit

Const NOD As Integer = 500

Const NOS As Integer = 4

Private Sub Form_Load()

With ChartFX1

.TypeEx = .TypeEx Or CTE_NOTITLESHADOW

.Chart3D = False

.Gallery = LINES

.Axis(AXIS_X).Grid = True

.Axis(AXIS_Y).Grid = True

' Allocate memory for chart and clear data

.OpenDataEx COD_XVALUES Or COD_REMOVE, NOS + 1, NOD

.OpenDataEx COD_VALUES Or COD_REMOVE, NOS + 1, NOD

.CloseData COD_VALUES

.CloseData COD_XVALUES

' Layout Settings.

.ToolBar = False

' UI Settings.

.AllowDrag = False

.AllowEdit = False

.ContextMenus = False

.ShowTips = True

.AllowResize = False

.MarkerShape = MK_NONE

.RGB2DBk = &H80000001

.BottomGap = 40

.RightGap = 13

.Border = False

' Title Font Settings.

.Axis(AXIS_Y).TitleFont.Size = 10

.Axis(AXIS_Y).TitleFont.Bold = True

.Axis(AXIS_X).TitleFont.Size = 10

.Axis(AXIS_X).TitleFont.Bold = True

.Fonts(CHART_TOPFT) = CF_BOLD

' Tool Windows Settings.

With .SerLegBoxObj

.BorderStyle = BBS_LINE

.Docked = TGFP_BOTTOM

.Font.Bold = True

.Moveable = False

.Sizeable = BAS_NORESIZE

.Visible = True

End With

' Configure X-axis of chart.

.Axis(AXIS_X).LogBase = 10

.Adm(CSA_XMIN) = 3

.Adm(CSA_XMAX) = 300

.DecimalsNum(CD_XLEG) = 0

' Configure Y-axis of chart

.Axis(AXIS_Y).LogBase = 10

.Adm(CSA_MIN) = 1

.Adm(CSA_MAX) = 250

.DecimalsNum(CD_YLEG) = 0

AddChartLabel 3

AddChartLabel 30

AddChartLabel 300

End With

End Sub

Private Sub AddChartLabel(ByVal dblValue As Double)

Dim AnnotX As Object

Dim cfxText As AnnText

Dim dx As Long

Dim dy As Long

With ChartFX1

.ValueToPixel dblValue, .Adm(CSA_MIN), dx, dy, AXIS_Y

Set AnnotX = New AnnotationX

.AddExtension AnnotX

AnnotX.ToolBar = False

End With

Set cfxText = AnnotX.Add(OBJECT_TYPE_TEXT, 0)

With cfxText

.Text = dblValue

.Align = LA_CENTER Or LA_BOTTOM

.AllowModify = False

.AllowMove = False

.BkColor = CHART_TRANSPARENT

.Height = TextHeight(.Text) / Screen.TwipsPerPixelY + 5

.Width = TextWidth(.Text) / Screen.TwipsPerPixelX + 6

.Left = dx - (.Width \ 2)

.Top = dy + 4

End With

End Sub

--------------------------------------------------------------------------

"SoftwareFX Support" <support@softwarefx.com> wrote in message

news:LKa7rqgvBHA.2668@webserver1.softwarefx.com...

> I'm afraid that will not be possible using regular X-Axis labels. The STEP

> is constant along all the axis, what you want is a "variable" step.

>

> You can use Annotation objects to add these 2 special labels at the

> beginning and end of the X axis.

>

> --

> FP

> Software FX, Inc.

>

>

Link to comment
Share on other sites

You can not call ValueToPixel until the chart has been drawn or at least its

layout is done.

If you are calling any function that retrieves scaling information, you must

do it after the chart is drawn or call UpdateSizeNow before.

The idea here is that the chart delays the RecalcLayout until the chart is

drawn to avoid unnecessary overhead.

--

FP

Software FX, Inc.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...