I'm trying to display some data using ZedGraph. The data was read in from a file, which is then stored in an array called heart_rate[x] which I'm trying to pass to the point pair list, however, it won't accept the string array. After searching, I assume it needs to be converted to double first. I've tried this but with no luck.
Here is the code that creates the array by reading data from a file. Ideally I don't want to change this, as I have other arrays written the same way, and this would require an entire program re-write.
for (x = 0; x < hrm_data.Length; x = x + 6)
{
heart_rate.Add(hrm_data[x]);
}
Here is where I set up ZedGraph, obviously missing code to pass the array to the point pair list.
GraphPane myPane = z_graph.GraphPane;
myPane.Title = "HRM Data";
myPane.XAxis.Title = "Time";
myPane.YAxis.Title = "Readings";
PointPairList heart_rate_list = new PointPairList();
LineItem heart_rate_curve = myPane.AddCurve("Heart Rate", heart_rate_list, Color.Red, SymbolType.Diamond);
z_graph.AxisChange();
EDIT
Here is an example of the file I'm reading in. The first column of data is heart rate readings, Using the for loop I am only selecting the first column and adding that to the array
91 43 56 78 45 78
91 43 56 78 45 78
91 43 56 78 45 78
91 43 56 78 45 78
EDIT 2
Thankyou for all the help, I really appreciate it, however, I think I'm confusing everyone with what I'm asking for. This is a student project and I know some fellow students have done this that could help out.
You should simply be able to take the string items of hrm_data
, split them, pick the first item of the split and convert into double
:s using the Double.Parse
method.
Then use the PointPairList(double[], double[])
constructor (see here) to create your desired point pair list:
PointPairList heart_rate_list = new PointPairList(
Enumerable.Range(0, hrm_data.Length).Select(i => (double)i).ToArray(),
hrm_data.Select(item => Double.Parse(item.Split(' ')[0])). ToArray());
Note that the x
coordinates are generated by creating an index collection which is cast to a double
collection.