鉴于缺乏文档,我对这个库仍然很粗糙。
我有一个 ChartPlotter 对象,它实时显示数据,因为它是通过从设备捕获数据捕获的。每次我有来自设备的新数据时,都会调用以下事件:
private void OnRawDataChanged(object sender, RawDataChangedEventArgs e)
{
System.Diagnostics.Debugger.Log(0, "event", "event received from data managern");
System.Diagnostics.Debugger.Log(0, "event", e.NewRawDataSet.Length + " tuples of data returnedn");
var batchSize = e.NewRawDataSet.Length;
// Expected tuples of 2 values + 2 threshold values
Point[][] points = new Point[4][];
for (int i = 0; i < 4; i++)
{
points[i] = new Point[batchSize];
}
double period = 1.0 / Properties.Settings.Default.SamplingRate;
for (int i = 0; i < batchSize; i++)
{
// Time is expressed in milliseconds
double t = e.NewRawDataSet[i].Time / 1000.0;
points[0][i] = new Point(t, e.NewRawDataSet[i].Sensors[0]);
points[1][i] = new Point(t, e.NewRawDataSet[i].Sensors[1]);
points[2][i] = new Point(t, parentForm.PressureHisteresysOpen);
points[3][i] = new Point(t, parentForm.PressureHisteresysClose);
}
plotter.Dispatcher.Invoke(DispatcherPriority.Normal,
new Action(() =>
{
sensor0.AppendMany(points[0]);
sensor1.AppendMany(points[1]);
pressureOpen.AppendMany(points[2]);
pressureClose.AppendMany(points[3]);
}));
}
使用海图仪的标准设置,图形将自动适应窗口。我希望水平轴自动向左滚动,仅显示捕获的最后 10 秒(例如)。有没有办法实现这一目标?
谢谢
为此,您必须修改绘图仪。ViewPort.Visible 属性。此属性采用使用值构造的 DataRect 对象以形成矩形。每次收到新数据时,都必须重新计算此矩形,以便图形滚动查看。
下面是构造 DataRect 的示例:
double yMin = 1;
double yMax = 10;
double xMin = 1;
double xMax = 10;
plotter.ViewPort.Visible = new DataRect(xMin, yMin, xMax - xMin, yMax - yMin);
您的最小值和最大值将基于轴上的数据类型。