Display HH:mm:ss in DateTime x axis in Chart C#

前端 未结 1 1410
故里飘歌
故里飘歌 2021-01-24 03:54

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

相关标签:
1条回答
  • 2021-01-24 04:51

    Solution 1:

    Try This:

    DateTime myDateValue = DateTime.Now;
    String XValueType  = myDateValue.ToString("HH:mm:ss");
    

    Solution 2:

    if you are using windows chart control then

    Try This:

    chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "HH:mm:ss";
    

    Solution 3: as you said in your below comments if you are showing only DateTime as a string it would be difficult while comparing.

    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.

    Try This:

    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);
    
    0 讨论(0)
提交回复
热议问题