1---XAML布局的设计 3层嵌套
2---绘制显示的表格 11x21
for (int i = 0; i <=10; i++) { Polyline line = new Polyline(); line.Stroke = new SolidColorBrush(Colors.Red); Point startPoint = new Point(0,i*30);//起点 Point endPoint = new Point(600,i*30);//终点 line.Points.Add(startPoint); line.Points.Add(endPoint); MyCanvas.Children.Add(line); } for (int i = 0; i <= 20;i++ ) { Polyline line = new Polyline(); line.Stroke = new SolidColorBrush(Colors.Red); Point startPoint = new Point(i*30,0); Point endPoint = new Point(i*30,600); line.Points.Add(startPoint); line.Points.Add(endPoint); MyCanvas.Children.Add(line); }
3---根据数据绘制变化曲线
ComSettingModel MyComSettingModel = new ComSettingModel(); private DispatcherTimer tm = new DispatcherTimer(); private PointCollection MyPointCollection = new PointCollection(); private Polyline MyPolyline = new Polyline(); ZigBee MyZigBee; private void Window_Loaded_1(object sender, RoutedEventArgs e) { MyComSettingModel.ZigbeeCom = "COM3"; MyZigBee = new ZigBee(MyComSettingModel); MyZigBee.Open(); MyPolyline.Stroke = new SolidColorBrush(Color.FromRgb(191, 71, 22)); MainCanvs.Children.Add(MyPolyline); MyPolyline.Points = MyPointCollection; //定时器设定 tm.Tick += new EventHandler(tm_Tick); tm.Interval = TimeSpan.FromSeconds(1.0); tm.Start(); } int count=0; void tm_Tick(object sender, EventArgs e) { MyZigBee.GetSet(); float temperature =float.Parse( MyZigBee.temperatureValue); Point pt = new Point(count * 6, 300 - temperature * 6); MyPointCollection.Add(pt); if (count <=100) { for (int i = 0; i < MyPointCollection.Count; i++) { Point npt = new Point(MyPointCollection[i].X, MyPointCollection[i].Y); MyPointCollection[i] = npt; } count++; } else { for (int i = 0; i < MyPointCollection.Count; i++) { Point Line = new Point(MyPointCollection[i].X -6, MyPointCollection[i].Y); MyPointCollection[i] = Line; } count = 100; } txtTest.Text = string.Format("变化值:{0}", temperature); }