2
0

FlowChart.xaml.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using LiveCharts;
  2. using LiveCharts.Wpf;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Windows.Controls;
  6. namespace FastGithub.UI
  7. {
  8. /// <summary>
  9. /// FlowChart.xaml 的交互逻辑
  10. /// </summary>
  11. public partial class FlowChart : UserControl
  12. {
  13. private readonly LineSeries readSeries = new LineSeries
  14. {
  15. Title = "上行速率",
  16. PointGeometry = null,
  17. Values = new ChartValues<double>()
  18. };
  19. private readonly LineSeries writeSeries = new LineSeries()
  20. {
  21. Title = "下行速率",
  22. PointGeometry = null,
  23. Values = new ChartValues<double>()
  24. };
  25. public SeriesCollection Series { get; } = new SeriesCollection();
  26. public List<string> Labels { get; } = new List<string>();
  27. public Func<double, string> YFormatter { get; } = value => $"{value:0.00}";
  28. public FlowChart()
  29. {
  30. InitializeComponent();
  31. this.Series.Add(this.readSeries);
  32. this.Series.Add(this.writeSeries);
  33. DataContext = this;
  34. }
  35. public void Add(FlowRate flowRate)
  36. {
  37. this.readSeries.Values.Add(flowRate.ReadRate / 1024);
  38. this.writeSeries.Values.Add(flowRate.WriteRate / 1024);
  39. this.Labels.Add(DateTime.Now.ToString("HH:mm:ss"));
  40. if (this.Labels.Count > 60)
  41. {
  42. this.readSeries.Values.RemoveAt(0);
  43. this.writeSeries.Values.RemoveAt(0);
  44. this.Labels.RemoveAt(0);
  45. }
  46. }
  47. }
  48. }