封装:WPF绘制曲线视图

一、目的:绘制简单轻量级的曲线视图

二、实现:

1、动画加载曲线

2、点击图例显示隐藏对应曲线

3、绘制标准基准线

4、绘制蒙板显示标准区域

 

曲线图示例:

封装:WPF绘制曲线视图_第1张图片

心电图示例:

三、实现代码

View:


                            
                            
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                             

ViewModel:

    ///  说明 
    partial class MainWindowViewModel
    {
        private List _collection = new List();
        ///  曲线图数据 
        public List Collection
        {
            get { return _collection; }
            set
            {
                _collection = value;
                RaisePropertyChanged("Collection");
            }
        }

        void Init()
        {
            RefreshCurveData();
        }

       public  void RefreshCurveData()
        {

            List collection = new List();

            CurveEntitySource entity = new CurveEntitySource();
            entity.Text = "长度(km)";
            entity.Color = Brushes.Red;
            entity.Marker = new CirclePointMarker();

            entity.Marker.Fill = Brushes.Red;

            for (int i = 0; i < 20; i++)
            {
                PointC point = new PointC();
                point.X = i;
                point.Y = i*i;
                point.Text = DateTime.Now.AddDays(i).ToString("yyyy-MM-dd");
                entity.Source.Add(point);

                this.MinValue = this.MinValue > point.X ? point.X : this.MinValue;
                this.MaxValue = this.MaxValue < point.X ? point.X : this.MaxValue;

            }
            collection.Add(entity);

            entity = new CurveEntitySource();
            entity.Text = "重量(kg)";
            entity.Color = Brushes.Orange;
            entity.Marker = new  T5PointMarker();

            entity.Marker.Fill = Brushes.Orange;

            for (int i = 0; i < 20; i++)
            {
                PointC point = new PointC();
                point.X = i;
                point.Y = (20-i) * (20 - i);
                point.Text = DateTime.Now.AddDays(i).ToString("yyyy-MM-dd");
                entity.Source.Add(point);

                this.MinValue = this.MinValue > point.X ? point.X : this.MinValue;
                this.MaxValue = this.MaxValue < point.X ? point.X : this.MaxValue;

            }
            collection.Add(entity);

            this.Collection = collection;

        }

        private double _maxValue = double.MinValue;
        ///  说明 
        public double MaxValue
        {
            get { return _maxValue; }
            set
            {
                _maxValue = value;
                RaisePropertyChanged("MaxValue");
            }
        }

        private double _minValue = double.MaxValue;
        ///  说明 
        public double MinValue
        {
            get { return _minValue; }
            set
            {
                _minValue = value;
                RaisePropertyChanged("MinValue");
            }
        }
    }

    partial class MainWindowViewModel : INotifyPropertyChanged
    {
        public MainWindowViewModel()
        {
            Init();
        }

        #region - MVVM -

        public event PropertyChangedEventHandler PropertyChanged;

        public void RaisePropertyChanged([CallerMemberName] string propertyName = "")
        {
            if (PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion
    }

结构设计:

封装:WPF绘制曲线视图_第2张图片

示例图片:

封装:WPF绘制曲线视图_第3张图片

封装:WPF绘制曲线视图_第4张图片

 

下载地址 :GitHut: https://github.com/HeBianGu/WpfChartProgram.git

 

 

你可能感兴趣的:(WPF,C#)