Jump to content
Software FX Community

Chart vs Axis Titles

User (Legacy)

Recommended Posts

I need to create a chart that has a two line title at the top (X2 Axis). I

also need to have the two lines be different font sizes. I thought I could

do a Chart.Title for the top and a Chart.Axis(AXIS_X2).Title for the second

line, but they both appear to be the same object. Is this true? And if so,

is there a way to have a two line chart title with a large print first line

and a smaller print second line?

I am creating a chart using the ChartFX .DLL (Client Server) and can not

have it added manually--such as with annotations.

Thanks for your help,

Sean Scott

Link to comment
Share on other sites

I ended up with something like the following code. It has been changed a

little because I am using the ChartFX DLL and I wanted the example to use

the ChartFX control. Also, I had to do a little tweaking to make the

procedure stand by itself. This code should run if you follow the following


Open a new EXE VB project

Add a reference to ChartFX Client Server Control and Annotation Extension


Place a ChartFX control on the form.

Paste the code from below into the form code window

Run it

Option Explicit

Private Enum eTitleAlignment

TitleAlignment_CENTER = 0

TitleAlignment_LEFT = 1

TitleAlignment_Right = 2

End Enum

Private Sub ProcessTitles(TitleFirst As String, TitleSecond As String,

TitleAlignment As eTitleAlignment)

Dim lHeight As Long

Dim Title1 As AnnText

Dim Title2 As AnnText

Dim AnnotX As AnnotationX

Dim ocBkColor As OLE_COLOR

Dim lBorderHeight As Long

Dim lIncreaseWidth As Long

Set AnnotX = New AnnotationX

ChartFX1.AddExtension AnnotX

Set Title1 = AnnotX.Add(OBJECT_TYPE_TEXT)

Set Title2 = AnnotX.Add(OBJECT_TYPE_TEXT)

ocBkColor = RGB(208, 208, 208)

lBorderHeight = 3

lIncreaseWidth = 1 'we will probably need to fudge the width a little

bit -- this is how much

'we have to test for an empty string, otherwise we could end up crashing

If Not TitleFirst = "" Then

With Title1

.Attach ATTACH_NONE, Null

.Text = TitleFirst

Title1.Font.Size = 12

'we have found that if you don't give Title1 (and Title2) a

height and width

'before you call SizeToFit, it doesn't work--so we have to set

them both to

'bogus heights and widths, then call size to fit to get them


'the right size, then increase the width a little bit because

SizeToFit sizes

'the text are just a little bit too small to show all the text.

One more quirk--

'if the original height & width is smaller than is necessary,

then SizeToFit

'doesn't work. This is why we set the original height and width

equal to the

'ChartFX1.Height and ChartFX1.Width since if the title needs to

be bigger than this

'we have much bigger problems to worry about than the title not

showing completely :)

.Height = ChartFX1.Height

.Width = ChartFX1.Width


.Width = .Width + lIncreaseWidth

.Top = lBorderHeight 'this gives us a nice margin at the top.

.BkColor = ocBkColor

.Refresh True

End With

End If

If Not TitleSecond = "" Then

With Title2

.Attach ATTACH_NONE, Null

.Text = TitleSecond

.Font.Size = 8

'see note in the TitleFirst section...

.Height = ChartFX1.Height

.Width = ChartFX1.Width


.Width = .Width + lIncreaseWidth

.Top = Title1.Height + lBorderHeight

.BkColor = ocBkColor

.Refresh True

End With

End If

Select Case TitleAlignment

Case TitleAlignment_CENTER

Title1.Left = (ChartFX1.Width \ 2 \ Screen.TwipsPerPixelX) -

(Title1.Width \ 2)

Title2.Left = (ChartFX1.Width \ 2 \ Screen.TwipsPerPixelX) -

(Title2.Width \ 2)

Case TitleAlignment_LEFT

Title1.Left = 0

Title2.Left = 0

Case TitleAlignment_Right

Title1.Left = (ChartFX1.Width \ Screen.TwipsPerPixelX) -

Title1.Width - 7

Title2.Left = (ChartFX1.Width \ Screen.TwipsPerPixelX) -

Title2.Width - 7

End Select

ChartFX1.TopGap = Title1.Height + Title2.Height + (lBorderHeight * 2)

Set AnnotX = Nothing

Set Title1 = Nothing

Set Title2 = Nothing

End Sub

Private Sub Form_Load()

With ChartFX1

.Gallery = BAR

'.Gallery = PIE


.ValueEx(0, 0) = 70

.ValueEx(0, 1) = 90

.ValueEx(0, 2) = 99

.ValueEx(0, 3) = 80

.ValueEx(0, 4) = 60


.Axis(AXIS_X).LabelAngle = 90

.Axis(AXIS_X).KeyLabel(0) = "Albert"

.Axis(AXIS_X).KeyLabel(1) = "Betty"

.Axis(AXIS_X).KeyLabel(2) = "Carl"

.Axis(AXIS_X).KeyLabel(3) = "Doug"

.Axis(AXIS_X).KeyLabel(4) = "Elaine"

.Axis(AXIS_X).Label(0) = "A"

.Axis(AXIS_X).Label(1) = "B"

.Axis(AXIS_X).Label(2) = "C"

.Axis(AXIS_X).Label(3) = "D"

.Axis(AXIS_X).Label(4) = "E"

End With

ProcessTitles "Main Title", "Sub Title", TitleAlignment_CENTER

End Sub

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


> There is only ONE top title in Chart FX 5.x, unlimited number of titles is


> new feature in Chart FX 6 (For .NET).


> A way to achieve this is using annotations, annotations don't require user

> intervention they can be created by code, check the Annotation Extension

> documentation for more details.


> --

> 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.

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.


  • Create New...