private void UpdateChart(DateTime?dateLowRange = null, DateTime?dateHighRange = null) { chartTrends.Series.Clear(); foreach (var info in _seriesNames.Cast <object[]>()) { var color = (Color)info[0]; var lineWidth = (int)info[1]; var chartType = (SeriesChartType)info[2]; var dashStyle = (ChartDashStyle)info[3]; var legendText = (string)info[4]; var toolTip = (string)info[5]; AddToSeries(legendText.StartsWith("HR0") ? "Legend2" : "Legend1", color, lineWidth, chartType, dashStyle, legendText, toolTip); } dateHighRange = dateHighRange ?? DateTime.Now - TimeSpan.FromMinutes(Offset); dateLowRange = dateLowRange ?? dateHighRange - new TimeSpan(0, _minutes, 0); Cursor = Cursors.WaitCursor; try { var trenddata = Data.LoadTrend(_riserName, (DateTime)dateLowRange, (DateTime)dateHighRange); var countSeries = _seriesNames.Count(); for (var i = 0; i < countSeries; i++) { chartTrends.Series[i].Points.Clear(); } foreach (var item in trenddata) { var snap = item.Key; var values = item.Value; const int step = 40; const int heigh = 20; var pos = 2600; var levlow = ScaleLow; var levhigh = ScaleHigh; for (var i = 0; i < countSeries; i++) { if (i >= values.Length) { continue; } var value = values[i]; var customvalue = value.ToString("0"); if (i == 3) { levlow = value; } if (i == 4) { levhigh = value; } if (i >= 7 && i <= 8) { customvalue = (value / 1000.0).ToString("F3"); value = Convert.ToInt32(ConvertValue(value, 20000, 4000, levhigh, levlow)); } if (i >= 9) { var visualLevel = DecPos(ref pos, step); var low = visualLevel; var high = visualLevel + heigh; value = value == 1 ? high : low; } var name = chartTrends.Series[i].Name; var visible = Data.Session.ReadBool("TrendShowed" + DisplayIndex, name, true); if (visible) { var pt = new DataPoint(chartTrends.Series[i]); pt.SetCustomProperty("Value", customvalue); pt.SetValueXY(snap, value); chartTrends.Series[i].Points.Add(pt); } else { chartTrends.Series[i].IsVisibleInLegend = false; } } } } finally { Cursor = Cursors.Default; } // добавляем точку справа, чтобы линия тренда заканчивалась на границе //if (_offset <= 0) //{ // x.Add(DateTime.Now.AddSeconds(-1)); // for (var i = 0; i < count; i++) y[i].Add(values[i]); //} chartTrends.ChartAreas[0].AxisX.Minimum = ((DateTime)dateLowRange).ToOADate(); chartTrends.ChartAreas[0].AxisX.Maximum = ((DateTime)dateHighRange).ToOADate(); AddCursorLine(CursorPosition < dateLowRange ? DateTime.Now.AddSeconds(-1) : CursorPosition); //InitTrendsList(); FillCursorsData(CursorPosition < dateLowRange ? DateTime.Now.AddSeconds(-1) : CursorPosition); // восстановление строки в таблице описания серий if (string.IsNullOrWhiteSpace(_lastSelected)) { return; } var lvi = lvTrends.FindItemWithText(_lastSelected); if (lvi == null) { return; } lvTrends.FocusedItem = lvi; lvi.Selected = true; lvTrends.EnsureVisible(lvi.Index); }