如何在X轴上制作标签时间值? [英] How do I make the labels on the X axis time values?

查看:92
本文介绍了如何在X轴上制作标签时间值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WinForm上有一个简单的图表。 我每秒都会向此图表添加数据。 当我添加数据时,我使用.AddXY并使用秒数计算X值。 该图表在x轴上显示与整数标签对应的秒数(由于每秒对数据进行采样,因此
与样本编号相同)。 我没有要求这些标签所以它必须是默认动作。

I have a simple Chart on a WinForm.  I add data to this chart every second.  When I add the data I use .AddXY and use a seconds count for the X value.  The chart appears with integer labels on the x axis corresponding to the seconds (which is the same as sample number since the data is being sampled every second).  I didn't ask for those labels so it must be a default action.

现在(因为我不知道更好!)我试图更改X轴上的标签时间戳 - 所以第61个标签将是1:01而不是61. 

Now (because I didn't know any better!) I am trying to change the labels on the X axis to time stamps - so that the 61st label will be 1:01 instead of 61. 

我已经研究了几个小时而没有在哪里。 

I've been researching this for several hours and getting no where. 

我需要做什么,在代码中,而不是在设计器中,将x轴上的标签作为时间戳而不是整数。  (实际上整数有时会变成实数。)

What do I have to do, in code, not in the designer, to get the labels on the x axis as timestamps instead of just integers.  (Actually the integers sometimes turn into real numbers.)

这让我疯了。 我非常感谢你的帮助。

This is driving me nuts.  I'd me very grateful for some help.

谢谢,  Bob

Thanks,  Bob

 

 

 

推荐答案

当图表点击Customize事件时,自动生成的标签将位于Axis.CustomLabels集合中。你可以在那里操纵它们。比如像这样的
(这可能会在每次更新图表时运行)


Private Sub Chart1_Customize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Chart1.Customize

	For Each lbl As CustomLabel In Chart1.ChartAreas(0).AxisX.CustomLabels

		Dim value As Double = CDbl(lbl.Text)
		Dim minutes As Double = Math.Floor(value / 60)
		Dim seconds As Double = value - minutes * 60

		lbl.Text = String.Format("{0:0}:{1:00}", minutes, seconds)

	Next

End Sub


这篇关于如何在X轴上制作标签时间值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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