Repository navigation
Expand file tree
/
Copy pathAnalysis.cs
More file actions
508 lines (459 loc) · 25.8 KB
/
Copy pathAnalysis.cs
File metadata and controls
508 lines (459 loc) · 25.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows.Forms.DataVisualization.Charting;
namespace NetPulse
{
internal sealed class SessionSample
{
public DateTime Timestamp;
public double ElapsedSeconds;
public string Mode;
public string TargetProcess;
public bool TargetRunning;
public double SystemCpu;
public double MaxLogicalCpu;
public double TargetCpu;
public double? GatewayPing;
public double? InternetPing;
public double Jitter;
public double GatewayLoss;
public double InternetLoss;
public double Download;
public double Upload;
}
internal sealed class SessionEvent
{
public DateTime Timestamp;
public string EventName;
public string State;
}
internal sealed class SessionData
{
public string SourcePath;
public string SessionFolder;
public string SessionCsvPath;
public string EventsCsvPath;
public readonly List<SessionSample> Samples = new List<SessionSample>();
public readonly List<SessionEvent> Events = new List<SessionEvent>();
}
internal static class SessionLoader
{
public static string FindLatestSession(string root)
{
if (string.IsNullOrWhiteSpace(root) || !Directory.Exists(root))
return null;
List<string> candidates = new List<string>();
try
{
foreach (string directory in Directory.GetDirectories(root))
{
string csv = Path.Combine(directory, "session.csv");
if (File.Exists(csv)) candidates.Add(csv);
}
candidates.AddRange(Directory.GetFiles(root, "session_*.csv", SearchOption.TopDirectoryOnly));
}
catch { }
return candidates
.OrderByDescending(path => SafeLastWrite(path))
.FirstOrDefault();
}
public static SessionData Load(string selectedPath)
{
if (string.IsNullOrWhiteSpace(selectedPath))
throw new InvalidOperationException("No session path was selected.");
string sessionCsv = ResolveSessionCsv(selectedPath);
if (sessionCsv == null)
throw new FileNotFoundException("No session.csv or legacy session_*.csv was found.");
SessionData data = new SessionData();
data.SourcePath = selectedPath;
data.SessionCsvPath = sessionCsv;
data.SessionFolder = Path.GetDirectoryName(sessionCsv);
data.EventsCsvPath = ResolveEventsCsv(sessionCsv);
LoadSamples(sessionCsv, data.Samples);
if (!string.IsNullOrWhiteSpace(data.EventsCsvPath) && File.Exists(data.EventsCsvPath))
LoadEvents(data.EventsCsvPath, data.Events);
return data;
}
private static string ResolveSessionCsv(string selectedPath)
{
if (File.Exists(selectedPath))
return selectedPath.EndsWith(".csv", StringComparison.OrdinalIgnoreCase) ? selectedPath : null;
if (!Directory.Exists(selectedPath))
return null;
string direct = Path.Combine(selectedPath, "session.csv");
if (File.Exists(direct)) return direct;
return FindLatestSession(selectedPath);
}
private static string ResolveEventsCsv(string sessionCsv)
{
string directory = Path.GetDirectoryName(sessionCsv);
if (Path.GetFileName(sessionCsv).Equals("session.csv", StringComparison.OrdinalIgnoreCase))
return Path.Combine(directory, "events.csv");
string name = Path.GetFileName(sessionCsv);
if (name.StartsWith("session_", StringComparison.OrdinalIgnoreCase))
return Path.Combine(directory, "events_" + name.Substring("session_".Length));
return null;
}
private static void LoadSamples(string path, List<SessionSample> destination)
{
using (StreamReader reader = new StreamReader(path, true))
{
string headerLine = reader.ReadLine();
if (headerLine == null) return;
List<string> headers = ParseCsvLine(headerLine);
Dictionary<string, int> indexes = BuildIndex(headers);
string line;
while ((line = reader.ReadLine()) != null)
{
if (line.Trim().Length == 0) continue;
List<string> values = ParseCsvLine(line);
DateTime timestamp;
if (!TryDate(Get(values, indexes, "TimestampLocal"), out timestamp)) continue;
SessionSample sample = new SessionSample();
sample.Timestamp = timestamp;
sample.ElapsedSeconds = Number(Get(values, indexes, "ElapsedSeconds"));
sample.Mode = Get(values, indexes, "Mode");
sample.TargetProcess = Get(values, indexes, "TargetProcess");
if (string.IsNullOrWhiteSpace(sample.TargetProcess)) sample.TargetProcess = "--";
string running = Get(values, indexes, "TargetProcessRunning");
if (running.Length == 0) running = Get(values, indexes, "ValorantRunning");
sample.TargetRunning = running == "1" || running.Equals("true", StringComparison.OrdinalIgnoreCase);
sample.SystemCpu = Number(Get(values, indexes, "SystemCpuPct"));
sample.MaxLogicalCpu = Number(Get(values, indexes, "MaxLogicalCpuPct"));
string targetCpu = Get(values, indexes, "TargetProcessCpuPct");
if (targetCpu.Length == 0) targetCpu = Get(values, indexes, "ValorantCpuPct");
sample.TargetCpu = Number(targetCpu);
sample.GatewayPing = NullableNumber(Get(values, indexes, "GatewayPingMs"));
sample.InternetPing = NullableNumber(Get(values, indexes, "InternetPingMs"));
sample.Jitter = Number(Get(values, indexes, "InternetJitterMs"));
sample.GatewayLoss = Number(Get(values, indexes, "GatewayLoss60Pct"));
sample.InternetLoss = Number(Get(values, indexes, "InternetLoss60Pct"));
sample.Download = Number(Get(values, indexes, "DownloadKBps"));
sample.Upload = Number(Get(values, indexes, "UploadKBps"));
destination.Add(sample);
}
}
}
private static void LoadEvents(string path, List<SessionEvent> destination)
{
using (StreamReader reader = new StreamReader(path, true))
{
string headerLine = reader.ReadLine();
if (headerLine == null) return;
Dictionary<string, int> indexes = BuildIndex(ParseCsvLine(headerLine));
string line;
while ((line = reader.ReadLine()) != null)
{
List<string> values = ParseCsvLine(line);
DateTime timestamp;
if (!TryDate(Get(values, indexes, "TimestampLocal"), out timestamp)) continue;
destination.Add(new SessionEvent
{
Timestamp = timestamp,
EventName = Get(values, indexes, "Event"),
State = Get(values, indexes, "State")
});
}
}
}
private static Dictionary<string, int> BuildIndex(List<string> headers)
{
Dictionary<string, int> result = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
for (int index = 0; index < headers.Count; index++) result[headers[index]] = index;
return result;
}
private static string Get(List<string> values, Dictionary<string, int> indexes, string name)
{
int index;
return indexes.TryGetValue(name, out index) && index >= 0 && index < values.Count ? values[index] : string.Empty;
}
private static double Number(string value)
{
double result;
return double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out result) ? result : 0;
}
private static double? NullableNumber(string value)
{
double result;
return double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out result) ? (double?)result : null;
}
private static bool TryDate(string value, out DateTime result)
{
return DateTime.TryParseExact(value, "yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture,
DateTimeStyles.AssumeLocal, out result) || DateTime.TryParse(value, CultureInfo.CurrentCulture, DateTimeStyles.AssumeLocal, out result);
}
private static DateTime SafeLastWrite(string path)
{
try { return File.GetLastWriteTime(path); }
catch { return DateTime.MinValue; }
}
private static List<string> ParseCsvLine(string line)
{
List<string> result = new List<string>();
System.Text.StringBuilder cell = new System.Text.StringBuilder();
bool quoted = false;
for (int index = 0; index < line.Length; index++)
{
char character = line[index];
if (character == '"')
{
if (quoted && index + 1 < line.Length && line[index + 1] == '"')
{
cell.Append('"');
index++;
}
else quoted = !quoted;
}
else if (character == ',' && !quoted)
{
result.Add(cell.ToString());
cell.Length = 0;
}
else cell.Append(character);
}
result.Add(cell.ToString());
return result;
}
}
internal sealed class SessionAnalysis
{
public int Samples;
public TimeSpan Duration;
public string TargetProcess;
public int TargetRunningSamples;
public double CpuAverage;
public double CpuP95;
public double CpuMaximum;
public double CoreP95;
public double CoreMaximum;
public int CpuHighSamples;
public int CoreHighSamples;
public double TargetCpuAverage;
public double TargetCpuMaximum;
public int GatewayFailures;
public double GatewayAverage;
public double GatewayMaximum;
public int GatewaySpikes;
public int InternetFailures;
public double InternetAverage;
public double InternetMaximum;
public int InternetSpikes;
public int Markers;
public int MarkerCpuCorrelations;
public int MarkerGatewayCorrelations;
public int MarkerInternetCorrelations;
public string BuildText(bool english)
{
List<string> lines = new List<string>();
lines.Add(english ? "SESSION OVERVIEW" : "工作階段摘要");
lines.Add(english ? "────────────────────────────────────────" : "────────────────────────────────────────");
lines.Add((english ? "Duration: " : "監測時間:") + FormatDuration(Duration));
lines.Add((english ? "Samples: " : "樣本數:") + Samples.ToString("N0", CultureInfo.InvariantCulture));
lines.Add((english ? "Target process: " : "監測程式:") + TargetProcess);
lines.Add((english ? "Target running time: " : "目標程式執行時間:") + FormatDuration(TimeSpan.FromSeconds(TargetRunningSamples)));
lines.Add(string.Empty);
lines.Add(english ? "CPU" : "CPU 分析");
lines.Add(string.Format(CultureInfo.InvariantCulture,
english ? "Average / P95 / Maximum: {0:0.0}% / {1:0.0}% / {2:0.0}%" : "平均/P95/最高:{0:0.0}%/{1:0.0}%/{2:0.0}%",
CpuAverage, CpuP95, CpuMaximum));
lines.Add(string.Format(CultureInfo.InvariantCulture,
english ? "Max logical core P95 / Maximum: {0:0.0}% / {1:0.0}%" : "最高邏輯核心 P95/最高:{0:0.0}%/{1:0.0}%",
CoreP95, CoreMaximum));
lines.Add(string.Format(CultureInfo.InvariantCulture,
english ? "CPU ≥90%: {0} samples | Logical core ≥95%: {1} samples" : "整體 CPU ≥90%:{0} 筆|單一核心 ≥95%:{1} 筆",
CpuHighSamples, CoreHighSamples));
lines.Add(string.Format(CultureInfo.InvariantCulture,
english ? "Target process average / maximum: {0:0.0}% / {1:0.0}%" : "目標程式 CPU 平均/最高:{0:0.0}%/{1:0.0}%",
TargetCpuAverage, TargetCpuMaximum));
lines.Add(string.Empty);
lines.Add(english ? "NETWORK" : "網路分析");
lines.Add(string.Format(CultureInfo.InvariantCulture,
english ? "Gateway average / maximum: {0:0.0} / {1:0.0} ms | failures: {2} | spikes: {3}" : "路由器平均/最高:{0:0.0}/{1:0.0} ms|失敗:{2}|尖峰:{3}",
GatewayAverage, GatewayMaximum, GatewayFailures, GatewaySpikes));
lines.Add(string.Format(CultureInfo.InvariantCulture,
english ? "Internet average / maximum: {0:0.0} / {1:0.0} ms | failures: {2} | spikes: {3}" : "外網平均/最高:{0:0.0}/{1:0.0} ms|失敗:{2}|尖峰:{3}",
InternetAverage, InternetMaximum, InternetFailures, InternetSpikes));
lines.Add(string.Empty);
lines.Add(english ? "MARKERS AND DIAGNOSIS" : "手動標記與診斷");
lines.Add(string.Format(CultureInfo.InvariantCulture,
english ? "Markers: {0} | CPU-related: {1} | gateway-related: {2} | internet-related: {3}" : "標記:{0}|與 CPU 異常接近:{1}|與路由器異常接近:{2}|與外網異常接近:{3}",
Markers, MarkerCpuCorrelations, MarkerGatewayCorrelations, MarkerInternetCorrelations));
double coreHighPercent = Samples > 0 ? CoreHighSamples * 100.0 / Samples : 0;
double cpuHighPercent = Samples > 0 ? CpuHighSamples * 100.0 / Samples : 0;
double gatewayFailurePercent = Samples > 0 ? GatewayFailures * 100.0 / Samples : 0;
double internetFailurePercent = Samples > 0 ? InternetFailures * 100.0 / Samples : 0;
if (coreHighPercent >= 5 || MarkerCpuCorrelations > 0)
lines.Add(english ? "Finding: Single-core CPU saturation is a likely cause of stutter or apparent in-game ping spikes." : "判斷:單核心 CPU 飽和很可能造成卡頓,或讓遊戲內顯示的 Ping 看起來瞬間升高。");
else if (cpuHighPercent >= 5)
lines.Add(english ? "Finding: Sustained total CPU pressure may affect game and network processing latency." : "判斷:整體 CPU 長時間高負載,可能影響遊戲與網路封包處理延遲。");
else
lines.Add(english ? "Finding: No sustained CPU bottleneck was found in this session." : "判斷:本次沒有發現持續性的 CPU 瓶頸。");
if (gatewayFailurePercent >= 0.5 || GatewaySpikes >= 3 || MarkerGatewayCorrelations > 0)
lines.Add(english ? "Finding: Local network, Ethernet cable, adapter, or router instability is present." : "判斷:區域網路、網路線、網卡或路由器存在不穩定跡象。");
else if (internetFailurePercent >= 2 || InternetSpikes >= 3 || MarkerInternetCorrelations > 0)
lines.Add(english ? "Finding: The external path or ISP shows instability while the gateway is comparatively stable." : "判斷:路由器端相對穩定,但外網路徑或 ISP 存在不穩定跡象。");
else
lines.Add(english ? "Finding: Network latency was generally stable in this session." : "判斷:本次網路延遲整體穩定。");
return string.Join(Environment.NewLine, lines.ToArray());
}
private static string FormatDuration(TimeSpan value)
{
return string.Format(CultureInfo.InvariantCulture, "{0:00}:{1:00}:{2:00}", (int)value.TotalHours, value.Minutes, value.Seconds);
}
}
internal static class SessionAnalyzer
{
public static SessionAnalysis Analyze(SessionData data)
{
SessionAnalysis result = new SessionAnalysis();
result.Samples = data.Samples.Count;
if (data.Samples.Count == 0) return result;
result.Duration = data.Samples.Count > 1
? data.Samples[data.Samples.Count - 1].Timestamp - data.Samples[0].Timestamp
: TimeSpan.Zero;
result.TargetProcess = data.Samples.Select(sample => sample.TargetProcess).FirstOrDefault(value => !string.IsNullOrWhiteSpace(value)) ?? "--";
result.TargetRunningSamples = data.Samples.Count(sample => sample.TargetRunning);
result.CpuAverage = data.Samples.Average(sample => sample.SystemCpu);
result.CpuP95 = Percentile(data.Samples.Select(sample => sample.SystemCpu), 95);
result.CpuMaximum = data.Samples.Max(sample => sample.SystemCpu);
result.CoreP95 = Percentile(data.Samples.Select(sample => sample.MaxLogicalCpu), 95);
result.CoreMaximum = data.Samples.Max(sample => sample.MaxLogicalCpu);
result.CpuHighSamples = data.Samples.Count(sample => sample.SystemCpu >= 90);
result.CoreHighSamples = data.Samples.Count(sample => sample.MaxLogicalCpu >= 95);
List<SessionSample> targetSamples = data.Samples.Where(sample => sample.TargetRunning).ToList();
result.TargetCpuAverage = targetSamples.Count > 0 ? targetSamples.Average(sample => sample.TargetCpu) : 0;
result.TargetCpuMaximum = targetSamples.Count > 0 ? targetSamples.Max(sample => sample.TargetCpu) : 0;
List<double> gateway = data.Samples.Where(sample => sample.GatewayPing.HasValue).Select(sample => sample.GatewayPing.Value).ToList();
result.GatewayFailures = data.Samples.Count - gateway.Count;
result.GatewayAverage = gateway.Count > 0 ? gateway.Average() : 0;
result.GatewayMaximum = gateway.Count > 0 ? gateway.Max() : 0;
result.GatewaySpikes = gateway.Count(value => value >= 20);
List<double> internet = data.Samples.Where(sample => sample.InternetPing.HasValue).Select(sample => sample.InternetPing.Value).ToList();
result.InternetFailures = data.Samples.Count - internet.Count;
result.InternetAverage = internet.Count > 0 ? internet.Average() : 0;
result.InternetMaximum = internet.Count > 0 ? internet.Max() : 0;
result.InternetSpikes = internet.Count(value => value >= 80);
List<SessionEvent> markers = data.Events.Where(item => item.EventName == "USER_MARKER").ToList();
result.Markers = markers.Count;
foreach (SessionEvent marker in markers)
{
List<SessionSample> nearby = data.Samples.Where(sample => Math.Abs((sample.Timestamp - marker.Timestamp).TotalSeconds) <= 10).ToList();
if (nearby.Any(sample => sample.SystemCpu >= 90 || sample.MaxLogicalCpu >= 95)) result.MarkerCpuCorrelations++;
if (nearby.Any(sample => !sample.GatewayPing.HasValue || sample.GatewayPing.Value >= 20)) result.MarkerGatewayCorrelations++;
if (nearby.Any(sample => !sample.InternetPing.HasValue || sample.InternetPing.Value >= 80)) result.MarkerInternetCorrelations++;
}
return result;
}
private static double Percentile(IEnumerable<double> values, double percentile)
{
List<double> sorted = values.OrderBy(value => value).ToList();
if (sorted.Count == 0) return 0;
double position = (sorted.Count - 1) * percentile / 100.0;
int lower = (int)Math.Floor(position);
int upper = (int)Math.Ceiling(position);
if (lower == upper) return sorted[lower];
return sorted[lower] * (upper - position) + sorted[upper] * (position - lower);
}
}
internal static class SessionChartBuilder
{
public static void Populate(Chart chart, SessionData data, bool english)
{
chart.Series.Clear();
chart.ChartAreas.Clear();
chart.Legends.Clear();
chart.BackColor = Color.White;
chart.Palette = ChartColorPalette.None;
ChartArea cpuArea = new ChartArea("CPU");
ConfigureArea(cpuArea, english ? "CPU usage (%)" : "CPU 使用率 (%)", 0, 100);
cpuArea.Position = new ElementPosition(5, 4, 92, 43);
cpuArea.InnerPlotPosition = new ElementPosition(8, 8, 88, 80);
cpuArea.AxisX.LabelStyle.Enabled = false;
AddThreshold(cpuArea, 95, Color.FromArgb(235, 87, 87));
chart.ChartAreas.Add(cpuArea);
ChartArea networkArea = new ChartArea("Network");
ConfigureArea(networkArea, english ? "Latency (ms)" : "延遲 (ms)", double.NaN, double.NaN);
networkArea.Position = new ElementPosition(5, 51, 92, 45);
networkArea.InnerPlotPosition = new ElementPosition(8, 5, 88, 78);
networkArea.AxisX.LabelStyle.Format = "HH:mm:ss";
networkArea.AxisX.LabelStyle.Angle = -25;
chart.ChartAreas.Add(networkArea);
Legend legend = new Legend("Legend");
legend.Docking = Docking.Top;
legend.Alignment = StringAlignment.Center;
legend.Font = new Font("Segoe UI", 8F);
chart.Legends.Add(legend);
Series totalCpu = CreateSeries(english ? "Total CPU" : "整體 CPU", "CPU", Color.FromArgb(31, 119, 180));
Series maxCore = CreateSeries(english ? "Max logical core" : "最高邏輯核心", "CPU", Color.FromArgb(238, 132, 45));
Series targetCpu = CreateSeries(english ? "Target process" : "目標程式", "CPU", Color.FromArgb(35, 154, 102));
bool hasTarget = data.Samples.Any(sample => !string.IsNullOrWhiteSpace(sample.TargetProcess) && sample.TargetProcess != "--");
Series gateway = CreateSeries(english ? "Gateway ping" : "路由器 Ping", "Network", Color.FromArgb(119, 86, 184));
Series internet = CreateSeries(english ? "Internet ping" : "外網 Ping", "Network", Color.FromArgb(214, 72, 72));
chart.Series.Add(totalCpu);
chart.Series.Add(maxCore);
if (hasTarget) chart.Series.Add(targetCpu);
chart.Series.Add(gateway);
chart.Series.Add(internet);
int step = Math.Max(1, (int)Math.Ceiling(data.Samples.Count / 1200.0));
for (int index = 0; index < data.Samples.Count; index += step)
{
SessionSample sample = data.Samples[index];
double x = sample.Timestamp.ToOADate();
totalCpu.Points.AddXY(x, sample.SystemCpu);
maxCore.Points.AddXY(x, sample.MaxLogicalCpu);
if (hasTarget) targetCpu.Points.AddXY(x, sample.TargetCpu);
if (sample.GatewayPing.HasValue) gateway.Points.AddXY(x, sample.GatewayPing.Value);
if (sample.InternetPing.HasValue) internet.Points.AddXY(x, sample.InternetPing.Value);
}
Series markers = new Series(english ? "Manual marker" : "手動標記");
markers.ChartArea = "CPU";
markers.ChartType = SeriesChartType.Point;
markers.MarkerStyle = MarkerStyle.Triangle;
markers.MarkerSize = 9;
markers.Color = Color.FromArgb(191, 48, 115);
markers.XValueType = ChartValueType.DateTime;
foreach (SessionEvent item in data.Events.Where(item => item.EventName == "USER_MARKER"))
markers.Points.AddXY(item.Timestamp.ToOADate(), 98);
chart.Series.Add(markers);
}
private static void ConfigureArea(ChartArea area, string title, double minimum, double maximum)
{
area.BackColor = Color.White;
area.AxisY.Title = title;
area.AxisY.TitleFont = new Font("Segoe UI", 8F);
area.AxisY.LabelStyle.Font = new Font("Segoe UI", 8F);
area.AxisX.LabelStyle.Font = new Font("Segoe UI", 8F);
area.AxisX.MajorGrid.LineColor = Color.FromArgb(238, 241, 245);
area.AxisY.MajorGrid.LineColor = Color.FromArgb(230, 234, 239);
area.AxisX.LineColor = Color.FromArgb(185, 193, 202);
area.AxisY.LineColor = Color.FromArgb(185, 193, 202);
if (!double.IsNaN(minimum)) area.AxisY.Minimum = minimum;
if (!double.IsNaN(maximum)) area.AxisY.Maximum = maximum;
}
private static Series CreateSeries(string name, string area, Color color)
{
Series series = new Series(name);
series.ChartArea = area;
series.ChartType = SeriesChartType.FastLine;
series.BorderWidth = 2;
series.Color = color;
series.XValueType = ChartValueType.DateTime;
series.ToolTip = "#SERIESNAME\n#VALX{HH:mm:ss}: #VALY{0.0}";
return series;
}
private static void AddThreshold(ChartArea area, double value, Color color)
{
StripLine line = new StripLine();
line.IntervalOffset = value;
line.StripWidth = 0;
line.BorderColor = color;
line.BorderDashStyle = ChartDashStyle.Dash;
line.BorderWidth = 1;
area.AxisY.StripLines.Add(line);
}
}
}