Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Auto Calc Number X Axis Labels

2 views
Skip to first unread message

David

unread,
May 13, 2009, 11:41:31 PM5/13/09
to
I wrote a simple 2D graph program to use in a picturebox.

I would like to automatically calculate the number of X Axis labels to
appear based on the number of points plotted. For example if there are 500
data points there needs to be enough space between the labels so the labels
are not so close together that each label doesn't over write each other, but
if there are only 10 points, the labels would adjust accordingly with
possibly more space between them. Naturally the labels that are placed need
to correlate to the graph points labeled.

I can manually force a "fudge" factor by hard coding how many labels but I
want to do this without having to enter in either the number of labels nor
the spacing between.

Any help appreciated.


Dee Earley

unread,
May 14, 2009, 5:00:27 AM5/14/09
to

Can't you get the count from the number of data points?

--
Dee Earley (dee.e...@icode.co.uk)
i-Catcher Development Team

iCode Systems

Larry Serflaten

unread,
May 14, 2009, 8:27:55 AM5/14/09
to

"David" <dw857...@earthlink.net> wrote

> I wrote a simple 2D graph program to use in a picturebox.
>
> I would like to automatically calculate the number of X Axis labels to
> appear based on the number of points plotted.

What trouble are you having?

To ease calculations, pick a scalemode and do all your work in that
one scalemode (Twips, Pixels, whatever works best for the situation).

You know how wide the display is, because you are plotting points
on it. You know how many points you want to plot. What you need
to find is the size of one lable. If they're numerical, you can normalize
to one format. If they are text, you'd have to do considerably more work.

Assuming they are numerical, (ex; 2.25, 2.50, 2.75, etc) they will all
be roughly (depending on font) the same size. Add 25% to the size of
one lable (for spacing between them) and you have a value you can divide
into the width of the display.

The whole number produced would be how many labels you have room for. From there you have to divide them up appropreately for
the data displayed.

What part are having trouble with?

LFS


David

unread,
May 14, 2009, 10:26:07 AM5/14/09
to
LFS

Thanks for response.

I don't believe dividing the width of the label + 25% (a fudge) into the
display width will work.

For example (assuming Pixels):

The PBox ScaleWidth = 640, and the label width = 50 and you are plotting 500
points, then the label will not align with the correct datapoint.


"Larry Serflaten" <serf...@usinternet.com> wrote in message
news:ewdiy8I1...@TK2MSFTNGP06.phx.gbl...

Larry Serflaten

unread,
May 14, 2009, 12:11:55 PM5/14/09
to

"David" <dw857...@earthlink.net> wrote

> Thanks for response.
>
> I don't believe dividing the width of the label + 25% (a fudge) into the
> display width will work.
>
> For example (assuming Pixels):
>
> The PBox ScaleWidth = 640, and the label width = 50 and you are plotting 500
> points, then the label will not align with the correct datapoint.

You indicated you would be adding labels to the X Axis, you cant put
500 labels on that one axis, you'll have to skip some.

If the display is 650 and a lable is 50 (incl. spacing) then you have room
for 13 labels. What is going to become of the other 487 data points that
need labels? They cant all have lables, you'll have to divide up the 13 you
have room for, among the 500 points that you have. Right?

LFS


David

unread,
May 14, 2009, 2:25:04 PM5/14/09
to
This is what I've put together so far, but hoping to come up with a generic
routine similiar to what MSChart might use.

Private Sub ShowLabels(picGraph As PictureBox, label() As String,
iLongestLabel As Integer)


Dim i As Integer
Dim iX As Integer
Dim iPrevLabelPos As Integer
Dim iXSpacing As Integer
Dim lbl As String

iX = picGraph.ScaleLeft
iXSpacing = 2
iPrevLabelPos = -1
iLongestLabel = picGraph.TextWidth("300") * 1.25
For i = 1 To iXDataPts

If iX > iPrevLabelPos Then

lbl = label(i)
picGraph.CurrentX = iX
picGraph.CurrentY = -0.1 * dblMaxY
' Call Locate(picGraph, iX, 100)
picGraph.Print lbl
iPrevLabelPos = iX + iLongestLabel
End If

iX = iX + iXSpacing

Next

Exit Sub


"Larry Serflaten" <serf...@usinternet.com> wrote in message

news:eerl95K1...@TK2MSFTNGP02.phx.gbl...

0 new messages