//public bool IsReading { get; set; } private void Read() { var r = new Random(); while (IsReading) { Thread.Sleep(150); var now = DateTime.Now; // 随机生成数,测试绘图效果;将ChartValues中的Value替换成想显示的值即可 _trend1 += r.Next(-8, 10); _trend2 += r.Next(-8, 10); _trend3 += r.Next(-8, 10); _trend4 += r.Next(-8, 10); ChartValues1.Add(new MeasureModel { DateTime = now, Value = ports.imus[0] // 左腿IMU //Value = _trend1 }); //ChartValues2.Add(new MeasureModel //{ // DateTime = now, // Value = _trend2 //}); ChartValues3.Add(new MeasureModel { DateTime = now, Value = ports.imus[1] // 右腿IMU //Value = _trend3 }); //ChartValues4.Add(new MeasureModel //{ // DateTime = now, // Value = _trend4 //}); SetAxisLimits(now); //lets only use the last NUM_POINTS values if (ChartValues1.Count > NUM_POINTS) { ChartValues1.RemoveAt(0); } //if (ChartValues2.Count > NUM_POINTS) ChartValues2.RemoveAt(0); if (ChartValues3.Count > NUM_POINTS) { ChartValues3.RemoveAt(0); } //if (ChartValues4.Count > NUM_POINTS) ChartValues4.RemoveAt(0); } }
private void Read() { var r = new Random(); while (IsReading) { Thread.Sleep(150); // 画图频率 var now = DateTime.Now; _trend1 += r.Next(-8, 10); // y轴取值 ChartValues1.Add(new MeasureModel { DateTime = now, Value = _trend1 }); _trend2 += r.Next(-8, 10); // y轴取值 ChartValues2.Add(new MeasureModel { DateTime = now, Value = _trend2 }); SetAxisLimits(now); //lets only use the last 150 values if (ChartValues1.Count > 150) { ChartValues1.RemoveAt(0); } if (ChartValues2.Count > 150) { ChartValues2.RemoveAt(0); } } }