TeeChart X轴标签格式 [英] TeeChart X Axis Label Formatting

查看:488
本文介绍了TeeChart X轴标签格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的TeeChart看起来不错,网格线/刻度线出现在我希望的位置,依此类推(X轴LabelStyle设置为talAuto)。现在,我需要格式化X轴标签,以便它们显示时间偏移而不是数据点编号。



我将LabelStyle更改为talMark,并正在处理图表的OnGetAxisLabel。问题是我的事件处理程序将针对每个X轴点而不是将LabelStyle设置为talAuto时显示标签的点调用。



如何设置内容向上,所以我的事件处理程序仅需要LabelLabel为talAuto时绘制的标签?



我正在使用C ++ Builder XE3和IDE随附的TeeChart版本。



更新受到Yeray评论的启发:



在LabelStyle设置为talAuto的情况下,我总是将-1的ValueIndex传递给我的事件处理程序。在查看LabelText时,我看到了ValueIndex中期望的值,但同时我也得到了相等数量的错误值(忽略非X轴值)。例如...



我的图表显示5个X轴值:200、400、600、800、1000。我的事件处理程序被依次调用10次。 :

  ValueIndex LabelText 
-1 937.5
-1 0
-1 240,000
-1 200
-1 239,800
-1 1,000
-1800
-1600
-1400
-1200

我不知道前5个值来自何处或为何调用事件处理程序。



注意:我删除了C ++ Builder标记,因为无论使用哪种语言,任何使用TeeChart的人都可以回答此问题;我正在使用BCB的事实对该问题并不重要。

解决方案


我已经将LabelStyle更改为talMark并正在处理图表的
OnGetAxisLabel。问题是我的事件处理程序被每个X轴点调用
,而不仅仅是将LabelStyle设置为talAuto时显示标签
的点。


右,使用 talMark LabelStyle ,轴将绘制标签作为系列中的点。
您可以使用 talAuto LabelStyle 来获取所需的标签数量,并且仍然可以格式化 OnGetAxisLabel 事件中的标签。






更新:


当我使用talAuto时,ValueIndex始终为-1,所以我不知道哪个
数据点与事件关联。


设置 talAuto 且该系列具有标签时,其行为类似于 talText talMark :这些字符串用于底部轴和 ValueIndex 可以使用 OnGetAxisLabel 事件。
设置 talAuto 但该系列没有标签时,其行为类似于 talValue :底轴计算在 Minimum Maximum Increment OnGetAxisLabel 事件中的 ValueIndex 无法使用,因为轴标签与序列点不对应。 / p>

我想您的系列中没有标签。否则,从 talAuto 更改为 talMark 不应更改任何内容。



因此您必须在一个或另一个之间做出决定。也许您可以使用 talValue (或 talAuto 不带标签)来获取所需标签的数量,并提取信息






或者,使用<$ c $会更容易c> CustomLabels 。它们将允许您控制轴标签的位置和文本,而无需任何事件。例如:

 过程TForm1.FormCreate(Sender:TObject); 
var i:整数;
开始
Chart1.View3D:= false;

Chart1.AddSeries(TBarSeries).FillSampleValues;

Chart1.Axes.Bottom.Items.Clear;
for i:= 0到Chart1 [0] .Count-1执行
Chart1.Axes.Bottom.Items.Add(Chart1 [0] .XValue [i],'label'+ IntToStr(i ));
结尾;


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.

解决方案

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.

Right, using the talMark LabelStyle, the axis will draw as many labels as points in the series. You can use the talAuto LabelStyle to get the number of labels you wish and you can still format the labels in the OnGetAxisLabel event.


UPDATE:

When I use talAuto, ValueIndex is always -1 so I have no idea which data point is associated with the event.

When talAuto is set and the series has labels, it behaves like talText and talMark: these strings are used in the bottom axis and the ValueIndex in OnGetAxisLabel event can be used. When talAuto is set but the series has no label, it behaves like talValue: the bottom axis calculates the labels to show in function of the Minimum, Maximum and Increment. The ValueIndex in OnGetAxisLabel 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 to talMark shouldn't change anything.

So you have to decide between one or the other. Maybe you can use talValue (or talAuto 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:

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1.View3D:=false;

  Chart1.AddSeries(TBarSeries).FillSampleValues;

  Chart1.Axes.Bottom.Items.Clear;
  for i:=0 to Chart1[0].Count-1 do
    Chart1.Axes.Bottom.Items.Add(Chart1[0].XValue[i], 'label ' + IntToStr(i));
end;

这篇关于TeeChart X轴标签格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆