diff --git a/FastGithub.UI/FlowChart.xaml b/FastGithub.UI/FlowChart.xaml
index 7871d10..15bb9dd 100644
--- a/FastGithub.UI/FlowChart.xaml
+++ b/FastGithub.UI/FlowChart.xaml
@@ -15,13 +15,18 @@
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
上行流量
diff --git a/FastGithub.UI/FlowChart.xaml.cs b/FastGithub.UI/FlowChart.xaml.cs
index bbe6f55..6774f84 100644
--- a/FastGithub.UI/FlowChart.xaml.cs
+++ b/FastGithub.UI/FlowChart.xaml.cs
@@ -1,8 +1,8 @@
using LiveCharts;
+using LiveCharts.Configurations;
using LiveCharts.Wpf;
using Newtonsoft.Json;
using System;
-using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows.Controls;
@@ -18,19 +18,24 @@ namespace FastGithub.UI
{
Title = "上行速率",
PointGeometry = null,
- Values = new ChartValues()
+ Values = new ChartValues()
};
private readonly LineSeries writeSeries = new LineSeries()
{
Title = "下行速率",
PointGeometry = null,
- Values = new ChartValues()
+ Values = new ChartValues()
};
- public SeriesCollection Series { get; } = new SeriesCollection();
+ private static DateTime GetDateTime(double timestamp) => new DateTime(1970, 1, 1).Add(TimeSpan.FromMilliseconds(timestamp)).ToLocalTime();
- public List Labels { get; } = new List();
+ private static double GetTimestamp(DateTime dateTime) => dateTime.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
+
+
+ public SeriesCollection Series { get; } = new SeriesCollection(Mappers.Xy().X(item => item.Timestamp).Y(item => item.Rate));
+
+ public Func XFormatter { get; } = timestamp => GetDateTime(timestamp).ToString("HH:mm:ss");
public Func YFormatter { get; } = value => $"{FlowStatistics.ToNetworkSizeString((long)value)}/s";
@@ -77,16 +82,29 @@ namespace FastGithub.UI
this.textBlockRead.Text = FlowStatistics.ToNetworkSizeString(flowStatistics.TotalRead);
this.textBlockWrite.Text = FlowStatistics.ToNetworkSizeString(flowStatistics.TotalWrite);
- this.readSeries.Values.Add(flowStatistics.ReadRate);
- this.writeSeries.Values.Add(flowStatistics.WriteRate);
- this.Labels.Add(DateTime.Now.ToString("HH:mm:ss"));
+ var timestamp = GetTimestamp(DateTime.Now);
+ this.readSeries.Values.Add(new RateItem(flowStatistics.ReadRate, timestamp));
+ this.writeSeries.Values.Add(new RateItem(flowStatistics.WriteRate, timestamp));
- if (this.Labels.Count > 60)
+ if (this.readSeries.Values.Count > 60)
{
this.readSeries.Values.RemoveAt(0);
this.writeSeries.Values.RemoveAt(0);
- this.Labels.RemoveAt(0);
}
}
+
+ private class RateItem
+ {
+ public double Rate { get; }
+
+ public double Timestamp { get; }
+
+ public RateItem(double rate, double timestamp)
+ {
+ this.Rate = rate;
+ this.Timestamp = timestamp;
+ }
+ }
+
}
}