显示HH:MM:SS中的DateTime X轴图表C# [英] Display HH:mm:ss in DateTime x axis in Chart C#
问题描述
我有一系列的数据(温度对时间)的,我想用 .NET 4.0。$的C
图
对象来绘制它$ C>的问题是,如果我选择的DateTime
为 XValueType
它显示有喜欢该系列 DD.MM.YYYY
但我想它显示为 HH:MM:SS
I have series of data (temperature vs time) and I want to plot it using Chart
object of .NET 4.0.
The problem is that if I choose DateTime
as the XValueType
for the series it is displayed like dd.mm.yyyy
but I want to display it as HH:mm:ss
.
我怎么能这样做?
感谢您的帮助
推荐答案
解决方案1:
试试这个:
DateTime myDateValue = DateTime.Now;
String XValueType = myDateValue.ToString("HH:mm:ss");
解决方案2:
如果您使用的是Windows图表控制,然后
if you are using windows chart control then
试试这个:
chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "HH:mm:ss";
解决方案3:作为您在下面的评论说,如果你只显示日期时间为一个字符串这将是困难的,而比较
Solution 3: as you said in your below comments if you are showing only DateTime as a string it would be difficult while comparing.
是的,这将是困难的,如果你只显示了时间
部分(HH:MM:SS)
作为字符串。
但如果你显示日期和时间,那么你可以再次将字符串转换回日期时间和执行转换。
Yes it would be difficult if you only show the Time
part (HH:mm:ss)
as string.
but if you display the Date and Time then you can again convert back the string to DateTime and perform conversion.
试试这个:
DateTime date=DateTime.Now;
axisLabel=date.ToString("dd.MM.yyyy HH:mm:ss");
您可以将日期时间字符串转换回日期时间如下:
you can convert the datetime string back to DateTime as below:
DateTime date = DateTime.ParseExact(axisLabel,"dd.MM.yyyy
HH:mm:ss",CultureInfo.InvariantCulture);
这篇关于显示HH:MM:SS中的DateTime X轴图表C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!