WPF使用DynamicDataDisplay画动态曲线

1.后台程序:加载一条随即曲线,横轴为时间


using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Windows;
using System.IO;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Globalization;
using System.Diagnostics;
using System.Windows.Threading;
using Microsoft.Research.DynamicDataDisplay;
using Microsoft.Research.DynamicDataDisplay.DataSources;
using Microsoft.Research.DynamicDataDisplay.PointMarkers;
using Microsoft.Research.DynamicDataDisplay.Charts.Navigation;

namespace WpfApplication2
{
    
    public partial class MainWindow : Window
    {
        Random random = new Random();
        private DispatcherTimer timer = new DispatcherTimer();
        CompositeDataSource compositeDataSource1;
        CompositeDataSource compositeDataSource2;

        EnumerableDataSource<DateTime> datesDataSource = null;
        EnumerableDataSource<int> numberOpenDataSource=null;
        EnumerableDataSource<int> numberClosedDataSource = null;

        List<DateTime> vardatetime = new List<DateTime>(); 
        int i = 0;

        List<int> numberOpen = new List<int>();
        List<int> numberClosed = new List<int>();
        /*
        int[] numberOpen = new int[100];
        int[] numberClosed = new int[100];
        */
        


        public MainWindow()
        {
            InitializeComponent();
            
          // Loaded += new RoutedEventHandler(Window_Loaded);
        }

        private void Window1_Loaded(object sender, EventArgs e)
        {

            DateTime tempDateTime = new DateTime();
            tempDateTime = DateTime.Now;

            vardatetime.Add(tempDateTime);

            numberOpen.Add(random.Next(40));
            numberClosed.Add(random.Next(100));
            


            datesDataSource.RaiseDataChanged();
            numberOpenDataSource.RaiseDataChanged();
            numberClosedDataSource.RaiseDataChanged();

        
        
         i++;
 
      } // Window1_Loaded() 
        private void Window_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
           
            DateTime tempDateTime=new DateTime();
            
                tempDateTime = DateTime.Now;
                vardatetime.Add(tempDateTime);
               
                numberOpen.Add(random.Next(40));
                numberClosed.Add(random.Next(100));
            
                

               

                
            i++;

            datesDataSource = new EnumerableDataSource<DateTime>(vardatetime);
            datesDataSource.SetXMapping(x => dateAxis.ConvertToDouble(x));

             numberOpenDataSource = new EnumerableDataSource<int>(numberOpen);
            numberOpenDataSource.SetYMapping(y => y);

            numberClosedDataSource = new EnumerableDataSource<int>(numberClosed);
            numberClosedDataSource.SetYMapping(y => y);

            compositeDataSource1 = new CompositeDataSource(datesDataSource, numberOpenDataSource);
            compositeDataSource2 = new CompositeDataSource(datesDataSource, numberClosedDataSource);

           
            plotter.AddLineGraph(compositeDataSource2, Colors.Green, 1, "Percentage2");
            plotter.Viewport.FitToView();
            
            
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += new EventHandler(Window1_Loaded);
            timer.IsEnabled = true;
            
           
           
        }
  } // class Window1
 
  
}

2.前台展示程序

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0" 
        Title="Window1" Loaded="Window_Loaded" WindowState="Normal" Height="800" Width="1280" Background="Wheat">
       
    <Grid>
        <d3:ChartPlotter Name="plotter" Margin="10,10,20,10">
            <d3:ChartPlotter.HorizontalAxis>
                <d3:HorizontalDateTimeAxis Name="dateAxis"/>
            </d3:ChartPlotter.HorizontalAxis>
            <d3:ChartPlotter.VerticalAxis>
                <d3:VerticalIntegerAxis Name="countAxis"/>
            </d3:ChartPlotter.VerticalAxis>

            <d3:Header FontFamily="Arial" Content="Bug Information"/>
            <d3:VerticalAxisTitle FontFamily="Arial" Content="Count"/>
            <d3:HorizontalAxisTitle FontFamily="Arial" Content="Date"/>
        </d3:ChartPlotter>
    </Grid>
</Window>


转载于:https://my.oschina.net/SearchVera/blog/136809

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值