WPF(5)---很据数据绘制趋势表

1---XAML布局的设计 3层嵌套

    <Grid>
        <Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Center" Height="300" VerticalAlignment="Center" Width="600"> 
            <Viewbox>
                <Canvas Height="300" Width="600" x:Name="MyCanvas" ClipToBounds="True"/>
            </Viewbox>
        </Border>
    </Grid>

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);    
        }

 

转载于:https://www.cnblogs.com/Probably/p/4605348.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值