private void DrawTimeDomain(bool fitView) { try { if (viewModel == null || viewModel.CurrentSnapshotContract == null) { return; } PointLineSeries series = m_chart.ViewXY.PointLineSeries[0]; PointLineSeries series1 = m_chart.ViewXY.PointLineSeries[1]; LineSeriesCursor lineSeriesCursor = m_chart.ViewXY.LineSeriesCursors[0]; int index = GetNearestPointIndex(series, lineSeriesCursor.ValueAtXAxis); if (index == -1) { if (series1.PointCount > 0) { m_chart.BeginUpdate(); series1.Clear(); m_chart.EndUpdate(); } return; } SeriesPoint point = series.Points[index]; Guid id = (Guid)point.Tag; SnapshotItemContract2 itemContract2 = viewModel.CurrentSnapshotContract.Item.Where(o => o.id == id).SingleOrDefault(); if (itemContract2 == null) { return; } ChannelDataContract channelData = itemContract2.Data; if (channelData != null) { int length = channelData.VData.Length / 4; SeriesPoint[] points = new SeriesPoint[length]; for (int i = 0; i < length; i++) { points[i].X = i; points[i].Y = BitConverter.ToSingle(channelData.VData, i * 4); } m_chart.BeginUpdate(); series1.Points = points; if (fitView) { m_chart.ViewXY.FitView(); } m_chart.EndUpdate(); } } catch (Exception ex) { _eventAggregator.GetEvent <ThrowExceptionEvent>().Publish(Tuple.Create <string, Exception>("数据回放-报警点趋势-时域", ex)); } }
private void DrawFrequencyDomain(bool fitView) { try { if (ViewModel == null || ViewModel.CurrentSnapshotContract == null) { return; } PointLineSeries series = m_chart.ViewXY.PointLineSeries[0]; PointLineSeries series1 = m_chart.ViewXY.PointLineSeries[1]; LineSeriesCursor lineSeriesCursor = m_chart.ViewXY.LineSeriesCursors[0]; int index = GetNearestPointIndex(series, lineSeriesCursor.ValueAtXAxis); if (index == -1) { if (series1.PointCount > 0) { m_chart.BeginUpdate(); series1.Clear(); m_chart.EndUpdate(); } return; } else { SeriesPoint point = series.Points[index]; Guid id = (Guid)point.Tag; //htzk123,数据 //SnapshotItemContract2 itemContract2 = ViewModel.CurrentSnapshotContract.Item.Where(o => o.id == id).SingleOrDefault(); //if (itemContract2 == null) return; //ChannelDataContract channelData = itemContract2.Data; //if (channelData != null) //{ // int length = channelData.VData.Length / 4; // double[] vdata = new double[length]; // for (int i = 0; i < length; i++) // { // vdata[i] = BitConverter.ToSingle(channelData.VData, i * 4); // } // double frequencyInterval = channelData.SampleFre / channelData.SamplePoint; // if (channelData.TriggerN == 2) // { // frequencyInterval = ((int)channelData.TeethNumber / 2) / length; // } // int frequencyLength = (int)(channelData.SamplePoint / 2.56); // var outputAmp = Algorithm.Instance.FFT2Action(vdata, channelData.SamplePoint); // m_chart.BeginUpdate(); // if (series1.Points==null||series1.Points.Length != frequencyLength) // { // series1.Points = new SeriesPoint[frequencyLength]; // } // for (int i = 0; i < frequencyLength; i++) // { // series1.Points[i].X = frequencyInterval * i; // series1.Points[i].Y = outputAmp[i]; // } // if (fitView) // { // m_chart.ViewXY.ZoomToFit(); // } // m_chart.EndUpdate(); //} } } catch (Exception ex) { _eventAggregator.GetEvent <ThrowExceptionEvent>().Publish(Tuple.Create <string, Exception>("数据回放-报警点趋势-频域", ex)); } }
private void ViewModel_SignalRefresh(IEnumerable <SignalToken> tokens, DateTime time, double size, bool refresh) { try { _chart.BeginUpdate(); _chart.ViewXY.PointLineSeries.ForEach(p => p.SeriesEventMarkers.Clear()); foreach (var token in tokens) { PointLineSeries series = _chart.ViewXY.PointLineSeries.Where(o => o.Tag == token).SingleOrDefault(); AxisY axisY = _chart.ViewXY.YAxes.Where(o => o.Tag == token).SingleOrDefault(); if (token is BaseDivfreSignalToken) { var divToken = token as BaseDivfreSignalToken; if (divToken.DataContracts != null && divToken.DataContracts.Count > 0)//加入数据 { SeriesPoint[] points = new SeriesPoint[divToken.DataContracts.Count]; for (int i = 0; i < points.Length; i++) { points[i].X = _chart.ViewXY.XAxes[0].DateTimeToAxisValue(divToken.DataContracts[i].ACQDatetime); points[i].Y = divToken.DataContracts[i].Result.Value; AddMarker(series, points[i], divToken.DataContracts[i].AlarmGrade); } series.Points = points; axisY.Title.Text = divToken.DisplayName + "(" + divToken.DataContracts[0].Unit + ")"; if (refresh == true) { axisY.Maximum = divToken.UpperLimit; axisY.Minimum = divToken.LowerLimit; } } else { series.Clear(); } } else if (token is BaseWaveSignalToken) { var vToken = token as BaseWaveSignalToken; if (vToken.DataContracts != null && vToken.DataContracts.Count > 0)//加入数据 { SeriesPoint[] points = new SeriesPoint[vToken.DataContracts.Count]; for (int i = 0; i < points.Length; i++) { points[i].X = _chart.ViewXY.XAxes[0].DateTimeToAxisValue(vToken.DataContracts[i].ACQDatetime); points[i].Y = vToken.DataContracts[i].Result.Value; AddMarker(series, points[i], vToken.DataContracts[i].AlarmGrade); } series.Points = points; axisY.Title.Text = vToken.DisplayName + "(" + vToken.DataContracts[0].Unit + ")"; if (refresh == true) { axisY.Maximum = vToken.UpperLimit; axisY.Minimum = vToken.LowerLimit; } } else { series.Clear(); } } else if (token is BaseAlarmSignalToken) { var anToken = token as BaseAlarmSignalToken; if (anToken.DataContracts != null && anToken.DataContracts.Count > 0)//加入数据 { SeriesPoint[] points = new SeriesPoint[anToken.DataContracts.Count]; for (int i = 0; i < points.Length; i++) { points[i].X = _chart.ViewXY.XAxes[0].DateTimeToAxisValue(anToken.DataContracts[i].ACQDatetime); points[i].Y = anToken.DataContracts[i].Result.Value; AddMarker(series, points[i], anToken.DataContracts[i].AlarmGrade); } series.Points = points; axisY.Title.Text = anToken.DisplayName + "(" + anToken.DataContracts[0].Unit + ")"; if (refresh == true) { axisY.Maximum = anToken.UpperLimit; axisY.Minimum = anToken.LowerLimit; } } else { series.Clear(); } } } _chart.ViewXY.XAxes[0].SetRange(_chart.ViewXY.XAxes[0].DateTimeToAxisValue(time), _chart.ViewXY.XAxes[0].DateTimeToAxisValue(time.AddHours(size))); _chart.EndUpdate(); if (tokens != null && tokens.Count() > 0) { if (_chart.ViewXY.LineSeriesCursors[0].ValueAtXAxis <_chart.ViewXY.XAxes[0].Minimum || _chart.ViewXY.LineSeriesCursors[0].ValueAtXAxis> _chart.ViewXY.XAxes[0].Maximum) { _chart.ViewXY.LineSeriesCursors[0].ValueAtXAxis = (_chart.ViewXY.XAxes[0].Minimum + _chart.ViewXY.XAxes[0].Maximum) / 2.0; } else { UpdateCursorResult(_chart.ViewXY.LineSeriesCursors[0].ValueAtXAxis); } } } catch (Exception ex) { EventAggregatorService.Instance.EventAggregator.GetEvent <ThrowExceptionEvent>().Publish(Tuple.Create <string, Exception>("趋势-数据翻页", ex)); _chart.EndUpdate(); } }