如何在数据标签中将时间值格式化为 HH:MM:SS

发布于 2024-12-08 00:25:29 字数 970 浏览 0 评论 0原文

所以我在水晶报告中有一个条形图。在此图表上,我在每个图表上附加了一个数据标签,以秒为单位显示图表的值,如下所示: 在此处输入图像描述 我想做的是将这个数据标签格式化为时间格式。因此,对于图中的每个条形,数据标签将以以下格式显示:

HH:MM:SS。

我可以使用以下公式来显示时间格式:

local NumberVar Sec;
local NumberVar ss;
local NumberVar mm;
local NumberVar hh;
local StringVar SSS;
local StringVar MMM;

Sec := Sum ({GetAlarmSummaryDataSet2Response/GetAlarmSummaryDataSet2Result/Items/AlarmSummaryItem2.StopTime}, {GetAlarmSummaryDataSet2Response/GetAlarmSummaryDataSet2Result/Items/AlarmSummaryItem2.Section}) ;
hh := Int (Sec/3600);
mm :=Int ((Sec/60)- (60* Int(Sec/3600 )));
If mm<10 then MMM := "0" & ToText (mm,0);
If mm>9 Then MMM := ToText(mm,0) ;

ss :=Sec-(3600 * hh ) - (60 * mm ) ;
If ss<10 then SSS := "0" & ToText (ss,0);
If ss>9 Then SSS := ToText(ss,0) ;

ToText ( hh,0) & ":" & MMM & ":" & SSS

但我不确定如何将此公式应用到数据标签上。

非常感谢任何帮助或建议。

谢谢

So i have a bar graph in crystal reports. On this graph i have a data label attached to each of the graphs that displays the value of the graph in seconds, which appears like so:
enter image description here
What i would like to do is format this data-label into a time formatting. So for each bar in the graph it would have the data-label appear in the following format:

HH:MM:SS.

i am able to get the time formatting to appear using the following formula:

local NumberVar Sec;
local NumberVar ss;
local NumberVar mm;
local NumberVar hh;
local StringVar SSS;
local StringVar MMM;

Sec := Sum ({GetAlarmSummaryDataSet2Response/GetAlarmSummaryDataSet2Result/Items/AlarmSummaryItem2.StopTime}, {GetAlarmSummaryDataSet2Response/GetAlarmSummaryDataSet2Result/Items/AlarmSummaryItem2.Section}) ;
hh := Int (Sec/3600);
mm :=Int ((Sec/60)- (60* Int(Sec/3600 )));
If mm<10 then MMM := "0" & ToText (mm,0);
If mm>9 Then MMM := ToText(mm,0) ;

ss :=Sec-(3600 * hh ) - (60 * mm ) ;
If ss<10 then SSS := "0" & ToText (ss,0);
If ss>9 Then SSS := ToText(ss,0) ;

ToText ( hh,0) & ":" & MMM & ":" & SSS

But what i am unsure of is how to implement this formula onto a data label.

Any help or suggestions are greatly appreciated.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独自唱情﹋歌 2024-12-15 00:25:29

您可以选择显示组名称,并且可以显示图表计算的汇总值并设置其格式,但无法提供自定义公式。使用 CR XI 中的图表库是不可能的。

我对这个问题的最终解决方法是:

  1. 修改值公式以消除聚合函数。 (这是必要的,因为 Crystal 不允许在组名称字段中使用聚合函数 - 请参阅#2。)
  2. 对于组名称,请指定一个包含要在提升板中显示的文本的公式。包括标签和格式化值,以 Chr(13) & 分隔。 Chr(10) 将它们放在不同的行上。
  3. 配置提升板以显示标签,而不是值。

要将其应用于您的问题,您需要进行以下更改:

  1. 消除聚合函数。当然,我不知道使用您的设置是否可以实现这一点。也许如果您使用的是 DBMS,则可以在数据到达 Crystal 之前使用 SQL 命令或存储过程来计算总和。
  2. 在立板或 X 轴上一起打印标签和值。

如果这对您的应用程序来说还不够好,您可以考虑 CRChart ,一个商业替代品,试图解决 Crystal 图表库有时严重的限制。 (我认为它太贵了。)我认为 @APPEND_DATATEXT 宏可以让您在提升板上放置自定义值,但您仍然需要将摘要移动到服务器。

You can choose to display the group name, and you can display and format the summarized value calculated by the chart, but you can't provide a custom formula. It just isn't possible using the chart library in CR XI.

My eventual workaround for this problem:

  1. Modify the value formula to eliminate the aggregate function. (This is necessary because Crystal won't allow an aggregate function in a group name field -- see #2.)
  2. For the group name, specify a formula with the text you want to display in the riser. Include both the label and the formatted value, separated by Chr(13) & Chr(10) to place them on separate lines.
  3. Configure the riser to display the label, not the value.

To apply this to your problem you'd need to make these changes:

  1. Eliminate the aggregate function. Of course I don't know if this will be possible using your setup. Perhaps if you're using a DBMS you could use a SQL command or a stored procedure to calculate the sum before the data reaches Crystal.
  2. Print the label and value together, either on the riser or the X-axis.

If that's not good enough for your application, you might consider CRChart, a commercial replacement which tries to address the sometimes-crippling limitations of Crystal's chart library. (I thought it was too pricey.) I think the @APPEND_DATATEXT macro would let you place a custom value on a riser, but you'd still need to move the summary to the server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文