TestViewModel.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using CommunityToolkit.Mvvm.ComponentModel;
  2. using OxyPlot;
  3. using OxyPlot.Axes;
  4. using OxyPlot.Legends;
  5. using OxyPlot.Series;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. namespace ivf_tl_Manage.ViewModels
  14. {
  15. public partial class TestViewModel : BaseViewModel
  16. {
  17. [ObservableProperty]
  18. private PlotModel _HistoryModel;
  19. public TestViewModel()
  20. {
  21. string s = "";
  22. ObservableCollection<DataPoint> TempDataPoints = new ObservableCollection<DataPoint>();
  23. ObservableCollection<DataPoint> PressureDataPoints = new ObservableCollection<DataPoint>();
  24. for (int i = 30; i < 100; i++)
  25. {
  26. TempDataPoints.Add(OxyPlot.Axes.DateTimeAxis.CreateDataPoint(DateTime.Now.AddHours(i), i));
  27. }
  28. HistoryModel = new PlotModel();
  29. //InterpolationAlgorithm = InterpolationAlgorithms.CanonicalSpline, 曲线连接
  30. LineSeries TempLineSeries = new LineSeries { Title = "温度", ItemsSource = TempDataPoints };
  31. LineSeries PressureLineSeries = new LineSeries { Title = "压力", ItemsSource = PressureDataPoints };
  32. TempLineSeries.TrackerFormatString = "时间:{2:G}\n温度:{4:0.00}";
  33. PressureLineSeries.TrackerFormatString = "时间:{2:G}\n压力:{4:0.00}";
  34. TempLineSeries.MarkerType = MarkerType.Circle;
  35. PressureLineSeries.MarkerType = MarkerType.Circle;
  36. var dateTimeAxisHistory = new DateTimeAxis();
  37. dateTimeAxisHistory.Position = AxisPosition.Bottom;
  38. dateTimeAxisHistory.Title = "时间2";
  39. dateTimeAxisHistory.TitleFontSize = 30;
  40. dateTimeAxisHistory.StringFormat = "MM-dd\r\nHH-mm";
  41. dateTimeAxisHistory.TitleFont = @"C:\PersonalSpace\work\SourceHanSansSC-VF.ttf";
  42. dateTimeAxisHistory.MinorIntervalType = DateTimeIntervalType.Days;
  43. dateTimeAxisHistory.IntervalType = DateTimeIntervalType.Days;
  44. dateTimeAxisHistory.IntervalLength = 120;
  45. dateTimeAxisHistory.MajorStep = 10;
  46. dateTimeAxisHistory.MinorStep = 10;
  47. HistoryModel.Axes.Add(dateTimeAxisHistory);
  48. var numAxisHistory = new LinearAxis();
  49. numAxisHistory.Position = AxisPosition.Left;
  50. numAxisHistory.Maximum = 100;
  51. numAxisHistory.Minimum = 0;
  52. HistoryModel.Axes.Add(numAxisHistory);
  53. HistoryModel.Series.Add(TempLineSeries);
  54. HistoryModel.Series.Add(PressureLineSeries);
  55. var a = HistoryModel.Legends;
  56. //HistoryModel.LegendPosition = LegendPosition.BottomCenter;
  57. //HistoryModel.LegendOrientation = LegendOrientation.Horizontal;
  58. //HistoryModel.LegendFontSize = 25;
  59. //HistoryModel.LegendPlacement = LegendPlacement.Outside;
  60. ////RealModel.LegendItemSpacing = 100;
  61. //HistoryModel.LegendSymbolLength = 60;
  62. }
  63. }
  64. }