Click here to Skip to main content
15,883,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I have a .CSV file with first column having time stamps(HH:mm:ss:mss).
I have imported these values into a data table in string format and I am trying to plot a graph with these values on Zed graph X axis.
While trying to convert it to double using,
double[] result1 = time.Select<string, double>(s => Double.Parse(s)).ToArray<double>();

I am getting an error.
As Zed graph accepts only double values, I am stuck trying to resolve this problem.

Can any one help me with this.

-Thanks in Advance.
Posted
Comments
Richard MacCutchan 27-Mar-14 7:27am    
You cannot parse a string in that format to a Double, as it is not recognisable by the parser. You will need to write your own parser routine to convert it first into a number of milliseconds.

For ecah value from your array:
1.First you should convert from time string value in DateTime objects by using DateTime.Parse();

2.Then convert the DateTime object to double value by using Ticks property;
 
Share this answer
 
Comments
MrutyunjayS 27-Mar-14 9:16am    
It is working fine with the above solution.
Thanks.
Raul Iloc 27-Mar-14 9:22am    
I am glad that I could help you!
MrutyunjayS 28-Mar-14 7:18am    
Hello,

the value in the array earlier was "10:56:18.449" and after using
"double[] result1 = time.Select<string, double="">(m => DateTime.Parse(m).Ticks).ToArray<double>();"
the value in result1 is "6.3531600978449E+17".
The graph being plotted has x axis values in this manner. Am I missing something in the conversion or the graph plotting.
Raul Iloc 28-Mar-14 7:25am    
Yes "Thicks" value is the representation as "double" number at the entire given date time object, so the result should be a big number that can be used as you want (make it smaller, use only first part of it, etc). Here is an example about Thicks: http://msdn.microsoft.com/en-us/library/system.datetime.ticks.aspx
MrutyunjayS 28-Mar-14 8:05am    
With Ticks I will be able to convert it to time format, but the array to be sent to zedgraph should be a double[].
I have set the X-Axis to type Date:
"myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.Scale.Format = "HH:mm:ss.fff";"
If possible can you give me some code snippet for this?
Try using Convert.ToDouble(s)
instead of Double.parse


If this doesn't work can you show us your error?
It is possible he doesn't recognises the string if the culture is different
 
Share this answer
 
v3
Comments
MrutyunjayS 27-Mar-14 8:05am    
Hello,
I tried using Convert.ToDouble(s), but got an exception stating the input string is not in correct format.
Let TimeSpan.TryParseExact[^] do the parsing. Then, get the number of milliseconds via the TotalMilliseconds[^] property. It's already a double.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900