自学内容网 自学内容网

wpf 保姆级教学 OxyPlot制作图表+AutoFixture模拟数据 示例

请添加图片描述

using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
using OxyPlot.Series;
using PropertyChanged;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Charts.Models
{
   
    [AddINotifyPropertyChangedInterface]
    public abstract class ChartBase<T>
    {
   
        public ChartBase()
        {
   
            InitTable();
        }

        protected virtual string ChartName {
    get; set; } = "";

        protected virtual string ChartXName {
    get; set; } = "";

        protected virtual string ChartYName {
    get; set; } = "";

        protected virtual double ChartXMin {
    get; set; } = double.NaN;

        protected virtual double ChartXMax {
    get; set; } = double.NaN;

        protected virtual double ChartXStep {
    get; set; } = double.NaN;

        protected virtual double ChartYMin {
    get; set; } = double.NaN;

        protected virtual double ChartYMax {
    get; set; } = double.NaN;

        protected virtual double ChartYStep {
    get; set; } = double.NaN;

        protected virtual void InitTable()
        {
   
            DataSrc = new();

            chartModel = new PlotModel()
            {
   
                Title = ChartName,
                IsLegendVisible = true,
                LegendMargin = 5,
                LegendPlacement = LegendPlacement.Outside,
                LegendOrientation = LegendOrientation.Horizontal,
                LegendPosition = LegendPosition.TopLeft,
                LegendFontSize = 15,
                PlotAreaBorderThickness = new OxyThickness(1, 0, 0, 1),
                TextColor = foreground,
                TitleColor = foreground,
                PlotAreaBorderColor = foreground,
            };

            InitX();
            InitY();
            InitGoalLine();
            InitGoalPoint();

            if(chart_X != null)
            {
   
                ChartModel.Axes.Add(chart_X);
            }

            if (chart_Y != null)
            {
   
                ChartModel.Axes.Add(chart_Y);
            }

            if(chart_X != null && chart_Y != null)
            {
   
                lineSeries = new LineSeries()
                {
   
                    //IsVisible = isShowAcResistance,
                    //Title = "奈奎斯特图",
                    MarkerType = MarkerType.Circle,
                    MarkerFill = OxyColors.Transparent,
                    MarkerStroke = OxyColors.DarkSeaGreen,
                    MarkerStrokeThickness = 1,
                    //StrokeThickness = seriesStrokeThickness,
                    Color = OxyColors.CadetBlue,
                    TextColor = foreground,
                    XAxisKey = "Chart_X",
                    YAxisKey = "Chart_Y",
                };

                ChartModel.Series.Add(lineSeries);
            }

            if(goalPoints!=null)
            {
   
                ChartModel.Series.Add(goalPoints);
            }

            if(goalLines!=null)
            {
   
                goalLines.ForEach(x => ChartModel.Annotations.Add(x));
            }

        }

        protected virtual void InitGoalPoint()
        {
   
           
        }

        OxyColor foreground = OxyColors.White;

        protected virtual void InitGoalLine()
        {
   
            //goalLines = new List<LineAnnotation>();

            //goalLines.Add(new LineAn

原文地址:https://blog.csdn.net/weixin_44291381/article/details/143509696

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!