WPF 및 C# (동적 데이터 표시)을 사용하여 플롯 실시간 신호, 신호 대 시간을 테스트 중입니다. 일단 신호가 생성되면 즉시 플롯 차트에 나타나야합니다. 신호는 매우 빠르게 생성 될 수 있습니다 (밀리 초 (0.001 초)). 가장 좋은 방법은 무엇입니까? 어떤 제안이라도 고맙습니다. 감사합니다.WPF 및 C# .net 3.5에서 실시간 신호를 플롯하는 방법은 무엇입니까?
편집 : 예제 코드는 높이 평가 될 것입니다. 여기
내가 시도 것입니다 :플롯 개시 :
#region Constructor
public SignalStatsDisplay()
{
InitializeComponent();
plotter.Legend.Remove();
_initialChildrenCount = plotter.Children.Count;
int count = plotter.Children.Count;
//do not remove the initial children
if (count > _initialChildrenCount)
{
for (int i = count - 1; i >= _initialChildrenCount; i--)
{
plotter.Children.RemoveAt(i);
}
}
_nColorChannels = 4;
_lineprofileColor = new Color[4];
_lineprofileColor[0] = Colors.Transparent;
_lineprofileColor[1] = Colors.Red;
_lineprofileColor[2] = Colors.Black;
_lineprofileColor[3] = Colors.Blue;
//LineGraph lg = new LineGraph();
LineAndMarker<MarkerPointsGraph> lg = new LineAndMarker<MarkerPointsGraph>();
CirclePointMarker pm = new CirclePointMarker { Size = 10, Fill = Brushes.Green };
// MarkerPointsGraph mpg = new MarkerPointsGraph();
if (_nColorChannels > 0) // plotter init
{
_dataX = new List<int[]>();
_dataY = new List<int[]>();
int[] dataXOneCh = new int[1];
int[] dataYOneCh = new int[1];
dataXOneCh[0] = 0;
dataYOneCh[0] = 0;
/*CirclePointMarker marker = new CirclePointMarker();
marker.Fill = new SolidColorBrush(_lineprofileColor[0]);
marker.Pen = new Pen(marker.Fill, 0);
marker.Size = 2;
int lineWidth = 1;*/
for (int i = 0; i < 4; i++)
{
_dataX.Add(dataXOneCh); // data x-y mapping init
_dataY.Add(dataYOneCh);
EnumerableDataSource<int> xOneCh = new EnumerableDataSource<int>(dataXOneCh);
EnumerableDataSource<int> yOneCh = new EnumerableDataSource<int>(dataYOneCh);
xOneCh.SetXMapping(xVal => xVal);
yOneCh.SetXMapping(yVal => yVal);
CompositeDataSource dsOneCh = new CompositeDataSource(xOneCh, yOneCh);
// LineProfileColorSetup();
lg = plotter.AddLineGraph(dsOneCh,
(new Pen(Brushes.Green, 2)),
pm,
(new PenDescription("Data")));
// lg = plotter.AddLineGraph(dsOneCh,
// Colors.Transparent,
// 2,
// "Data");
// pm.FilteringEnabled = false;
}
plotter.FitToView();
}
else
{
return;
}
}
데이터 업데이트 : 신호가 매우 지방에 올 때
이for (int i = 0; i < 1; i++)
{
if (_dataX[i].Length == _dataY[i].Length)
{
EnumerableDataSource<int> xOneCh = new EnumerableDataSource<int>(_dataX[i]);
xOneCh.SetXMapping(xVal => xVal);
EnumerableDataSource<int> yOneCh = new EnumerableDataSource<int>(_dataY[i]);
yOneCh.SetYMapping(yVal => yVal);
CompositeDataSource ds = new CompositeDataSource(xOneCh, yOneCh);
Action UpdateData = delegate()
{
// ((LineGraph)plotter.Children.ElementAt(startIndex + i)).DataSource = ds;
// ((LineGraph)plotter.Children.ElementAt(startIndex + i)).LinePen = new Pen(new SolidColorBrush(Colors.Green), 1);
// ((PointsGraphBase)plotter.Children.ElementAt(startIndex + i)).DataSource = ds;
((PointsGraphBase)plotter.Children.ElementAt(startIndex + i + 1)).DataSource = ds;
// }
// (plotter.Children.ElementAt(startIndex + i)).DataSource = ds;
};
this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, UpdateData);
}
}
내가 가진 문제는, 새로운 말을한다 신호가 1 초마다 생성됩니다. 그래프는 1 초마다 새로운 마커를 생성하는 것으로 보이는데, 이해가 안갑니다.
기본 아이디어는 plotter.AddLineGraph를 생성 한 다음 DataSource 만 업데이트하는 것입니다. 하지만 작동하지 않는 것 같습니다. 그래서 나는 아마도 내가 잘못된 방향으로 가고 있다고 생각했습니다.
저는 C# 또는 WPF 전문가가 아닙니다. LineAndMarker가 예상대로 작동하지 않을 때 나는 의심하기 시작했습니다. 그래서 사람들이 WPF와 C#을 사용하여 실시간 신호 (급격하게 변화하는 샘플 간 시간 간격이 밀리 초일 수 있음)를 표시하는 일반적인 방법이 무엇인지 궁금합니다.
어떤 종류의 신호가 나옵니까? 어떻게 신호를 생성하고 싶습니까? 어떤 코드가 있습니까 ??? –
나는 그것이 어떤 종류의 신호인지에 관계가 있는지 궁금합니다. –
@NickTsui : 그럴 수도 있습니다. 매 ms마다 포인트를 추가하려고하면 계속 유지하기가 어려울 것입니다. 문제는 모든 데이터가 필요하다는 것입니다. 당신은 * nth * 포인트를 매번 그릴 수 있습니까? 모든 데이터를 기록해야합니까? 모든 데이터를 메모리에 보관해야합니까? –