using CommunityToolkit.Mvvm.ComponentModel; using OxyPlot; using OxyPlot.Axes; using OxyPlot.Legends; using OxyPlot.Series; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace ivf_tl_Manage.ViewModels { public partial class TestViewModel : BaseViewModel { [ObservableProperty] private PlotModel _HistoryModel; public TestViewModel() { string s = ""; ObservableCollection TempDataPoints = new ObservableCollection(); ObservableCollection PressureDataPoints = new ObservableCollection(); for (int i = 30; i < 100; i++) { TempDataPoints.Add(OxyPlot.Axes.DateTimeAxis.CreateDataPoint(DateTime.Now.AddHours(i), i)); } HistoryModel = new PlotModel(); //InterpolationAlgorithm = InterpolationAlgorithms.CanonicalSpline, 曲线连接 LineSeries TempLineSeries = new LineSeries { Title = "温度", ItemsSource = TempDataPoints }; LineSeries PressureLineSeries = new LineSeries { Title = "压力", ItemsSource = PressureDataPoints }; TempLineSeries.TrackerFormatString = "时间:{2:G}\n温度:{4:0.00}"; PressureLineSeries.TrackerFormatString = "时间:{2:G}\n压力:{4:0.00}"; TempLineSeries.MarkerType = MarkerType.Circle; PressureLineSeries.MarkerType = MarkerType.Circle; var dateTimeAxisHistory = new DateTimeAxis(); dateTimeAxisHistory.Position = AxisPosition.Bottom; dateTimeAxisHistory.Title = "时间2"; dateTimeAxisHistory.TitleFontSize = 30; dateTimeAxisHistory.StringFormat = "MM-dd\r\nHH-mm"; dateTimeAxisHistory.TitleFont = @"C:\PersonalSpace\work\SourceHanSansSC-VF.ttf"; dateTimeAxisHistory.MinorIntervalType = DateTimeIntervalType.Days; dateTimeAxisHistory.IntervalType = DateTimeIntervalType.Days; dateTimeAxisHistory.IntervalLength = 120; dateTimeAxisHistory.MajorStep = 10; dateTimeAxisHistory.MinorStep = 10; HistoryModel.Axes.Add(dateTimeAxisHistory); var numAxisHistory = new LinearAxis(); numAxisHistory.Position = AxisPosition.Left; numAxisHistory.Maximum = 100; numAxisHistory.Minimum = 0; HistoryModel.Axes.Add(numAxisHistory); HistoryModel.Series.Add(TempLineSeries); HistoryModel.Series.Add(PressureLineSeries); var a = HistoryModel.Legends; //HistoryModel.LegendPosition = LegendPosition.BottomCenter; //HistoryModel.LegendOrientation = LegendOrientation.Horizontal; //HistoryModel.LegendFontSize = 25; //HistoryModel.LegendPlacement = LegendPlacement.Outside; ////RealModel.LegendItemSpacing = 100; //HistoryModel.LegendSymbolLength = 60; } } }