MS Chart with Time x Axis like 00:00:00 and x value data in millisecond and increase data in run time

250 Views Asked by At

I have some millions rows of data starting from 0 to 20,000,000 with step 10. This data are time series (in milliseconds) received from my device that is connected to my PC.

I want to plot this data as x value with their y values, and I want to have an x-axis label like 00:00:00. My data received is live and I want to have a live plot.

Please give me some code for config MS Chart to have this plot

1

There are 1 best solutions below

0
Bron Davies On

First I am going to assume your data is a DateTime or DateTimeOffset. In order to specify a format for the DateTime values on the X-axis you would use something like this:

MyChart.ChartAreas[0].AxisX.LabelStyle.Format = "hh:mm:ss.fff";

Also see Custom date and time formats in the Microsoft documentation

However, if you want a TimeSpan type of value format, you will have to convert the DateTime (or milliseconds) to a TimeSpan instead and it should format as you would expect automatically. Otherwise, you can use a custom TimeSpan format string.

If you only have a milliseconds value, then you will have to convert that to a TimeSpan using TimeSpan.FromMilliseconds(ms)

A little more detail about what your data models look like would help provide more clarity.

Let me know if that helps or not.