I’ve got my TeeChart looking pretty good, the grid lines / ticks appear where I wish and so forth (the X Axis LabelStyle is set to talAuto). Now I need to format the X Axis labels so they display a time offset rather than the data point number.
I’ve changed the LabelStyle to talMark and am handling the chart’s OnGetAxisLabel. The problem is that my event handler is called for every X Axis point rather than just the points which displayed labels when I had LabelStyle set to talAuto.
How can I set things up so my event handler is only called for the labels which were drawn when LabelStyle was talAuto?
I’m using C++ Builder XE3 and the version of TeeChart included with IDE.
UPDATE inspired by Yeray's comment:
With LabelStyle set to talAuto I always get ValueIndex of -1 passed to my event handler. In looking at the LabelText, I see values that I would have expected in ValueIndex, but I also get an equal number of incorrect values (ignoring non-X Axis values). For example...
My chart displays 5 X-Axis values: 200, 400, 600, 800, 1000. My event handler is called 10 times, in this order:
ValueIndex LabelText
-1 937.5
-1 0
-1 240,000
-1 200
-1 239,800
-1 1,000
-1 800
-1 600
-1 400
-1 200
I have no idea where the first 5 values came from or why my event handler was called.
NOTE: I removed the C++ Builder tag because this question might be answered by anyone using TeeChart regardless of their language; the fact that I'm using BCB is not important to the question.
Right, using the
talMark
LabelStyle
, the axis will draw as many labels as points in the series. You can use thetalAuto
LabelStyle
to get the number of labels you wish and you can still format the labels in theOnGetAxisLabel
event.UPDATE:
When
talAuto
is set and the series has labels, it behaves liketalText
andtalMark
: these strings are used in the bottom axis and theValueIndex
inOnGetAxisLabel
event can be used. WhentalAuto
is set but the series has no label, it behaves liketalValue
: the bottom axis calculates the labels to show in function of theMinimum
,Maximum
andIncrement
. TheValueIndex
inOnGetAxisLabel
event can't be used because the axis labels don't correspond to a series point.I guess you don't have labels in your series. Otherwise, changing from
talAuto
totalMark
shouldn't change anything.So you have to decide between one or the other. Maybe you can use
talValue
(ortalAuto
without labels) to get the number of labels you wish, and extract the info you need from the string that is going to be drawn.Alternatively, it could be easier to use
CustomLabels
. They will allow you to control both the positions and the text of the axis labels without needing any event. In example: