/// <summary> /// Gets data from a series using the Points collection. /// </summary> /// <param name="s">reference to a series object</param> /// <param name="g_data">reference to a GraphDataForm object</param> /// <param name="hastime">specify whether series has time axis</param> private void GetDataPoints(Series s, GraphDataForm g_data, bool hastime) { string time = null; //iterate through all points in series //If the collection is empty, use an iterator foreach (SeriesPoint point in s) { if (hastime) { //decode time to hh:mm:ss time = DecodeTime(point.RelativeTime); } else { //series doesn't have a time axis time = point.RelativeTime.ToString(); } //create an array of points string[] columns = new string[point.Values.Count]; for (int i = 0; i < point.Values.Count; i++) { columns[i] = point.Values[i].Value.ToString("0.00000000");//all points are calculated with 8 digits precision } //assign created array to ListView g_data.ListBeginUpdate(); g_data.FillFirstColumn(time).SubItems.AddRange(columns); g_data.ListEndUpdate(); } /* Use the following code if you need to fire a SeriesLoadPoints event * * string time = null; * * for (int i = 0; i < s.Points.Count; i++) * { * if (hastime) * { * //decode time to hh:mm:ss * time = DecodeTime(point.RelativeTime); * } * else * { * //series doesn't have a time axis * time = s.Points[i].RelativeTime.ToString(); * } * * //create an array with all points * string[] columns = new string[s.Points[i].Values.Count]; * for (int y = 0; y < s.Points[i].Values.Count; y++) * columns[y] = s.Points[i].Values[y].Value.ToString("0.00000000"); * * //assign created array to ListView * g_data.ListBeginUpdate(); * g_data.FillFirstColumn(time).SubItems.AddRange(columns); * g_data.ListEndUpdate(); * } * */ }
/// <summary> /// Gets data for the specified series and populates the ListView. /// </summary> /// <param name="s">reference to a series object</param> /// <param name="g_data">reference to a GraphDataForm object</param> /// <param name="hastime">specify whether series has time axis</param> /// <param name="use_iterator">specify whether to use iterator when extracting data or not</param> private void FillDataIntoListView(Series s, GraphDataForm g_data, bool hastime, bool use_iterator) { if (!use_iterator) { //get data using Points collection GetDataPoints(s, g_data, hastime); } else { //get data using iterator GetDataWithIterator(s, g_data, hastime); } }
/// <summary> /// Extracts data for the specified graph and populates the ListView with the data. /// </summary> /// <param name="graph_name">name of graph</param> /// <param name="series_name">name of series to be extracted</param> /// <param name="g_data">reference to a GraphDataForm object</param> /// <param name="use_iterator">specify whether to use an iterator when extracting data</param> public void OpenGraphData(string graph_name, string series_name, GraphDataForm g_data, bool use_iterator) { if (_currentSession.IsOpenedOrCreated == false) { return; } Graph current_graph = null; if (null == g_data) { g_data = new GraphDataForm(); } GraphsList g_list = _currentRun.Graphs; Series current_series = null; current_graph = g_list[graph_name]; current_series = current_graph.Series[series_name]; //PointsDefinition class used to get names of values for (int i = 0; i < current_series.PointsDefinition.Count; i++) { g_data.AddColumnToListView(current_series.PointsDefinition[i].Name); } //add all graph series to ComboBox foreach (Series s in current_graph.Series) { g_data.AddSeries(s.Name); } //select current series g_data.SelectSeries(current_series.Name); g_data.Text = current_graph.Name.DisplayName; g_data.CurrentGraphName = current_graph.Name.Name; //fill ListView with data of current series FillDataIntoListView(current_series, g_data, current_graph.HasTimeAxis, use_iterator); _lastGraph = current_graph.Name.Name; //show the form if (false == g_data.Visible) { g_data.ShowDialog(); } }
/// <summary> /// Gets data from a series using an iterator. /// </summary> /// <param name="s">reference to a series object</param> /// <param name="g_data">reference to a GraphDataForm object</param> /// <param name="hastime">specify whether series has time axis</param> private void GetDataWithIterator(Series s, GraphDataForm g_data, bool hastime) { //check if iterator can be used if (!s.CanUsePointsIterator()) { MessageBox.Show("Iterator cannot be used"); return; } //get iterator SeriesPointIterator pi = s.GetPointsIterator(); string time = null; //iterate through all points using iterator foreach (SeriesPoint pt in pi) { if (hastime) { //decode time to hh:mm:ss time = DecodeTime(pt.RelativeTime); } else { //series doesn't have a time axis time = pt.RelativeTime.ToString(); } //create an array with all points string[] columns = new string[pt.Values.Count]; for (int i = 0; i < pt.Values.Count; i++) { columns[i] = pt.Values[i].Value.ToString("0.00000000"); } //assign created array to ListView g_data.ListBeginUpdate(); g_data.FillFirstColumn(time).SubItems.AddRange(columns); g_data.ListEndUpdate(); } }