-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathChartWindow.xaml.cs
208 lines (191 loc) · 6.68 KB
/
ChartWindow.xaml.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.DataVisualization.Charting;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace HoppoPlugin
{
/// <summary>
/// Interaction logic for ChartWindow.xaml
/// </summary>
public partial class ChartWindow : Window
{
public ChartWindow()
{
InitializeComponent();
LineChart1.Title = "正在生成统计图,请稍等。。。";
Thread t = new Thread(initializeChart);
t.Start();
}
private void initializeChart()
{
try
{
loadMatChart();
}
catch (Exception ex)
{
MessageBox.Show("加载统计图错误! " + ex.ToString());
}
}
private void loadMatChart()
{
List<string[]> loadedList = ReadCSV(UniversalConstants.CurrentDirectory + "MaterialsLog.csv");
List<MatData> fuelData = loadFuel(loadedList);
List<MatData> ammoData = loadFuel(loadedList);
List<MatData> steelData = loadFuel(loadedList);
List<MatData> bauxiteData = loadFuel(loadedList);
this.Dispatcher.Invoke(new Action(() =>
{
LineSeries fuelLine = LineChart1.Series[0] as LineSeries;
fuelLine.ItemsSource = fuelData;
LineSeries ammoLine = LineChart1.Series[1] as LineSeries;
ammoLine.ItemsSource = ammoData;
LineSeries steelLine = LineChart1.Series[2] as LineSeries;
steelLine.ItemsSource = steelData;
LineSeries bauxiteLine = LineChart1.Series[3] as LineSeries;
bauxiteLine.ItemsSource = bauxiteData;
LineChart1.Title = "资源统计图";
}));
}
private List<MatData> loadBauxite(List<string[]> loadMat)
{
List<MatData> matdata = new List<MatData>();
int lenth = loadMat.Count;
int quarter = lenth / 4;
for (int i = 0; i < loadMat.Count; i++)
{
if (i == 0)
{
matdata.Add(new MatData(loadMat[i][0], Int32.Parse(loadMat[i][4])));
}
else
{
if (quarter == i || quarter * 2 == i || quarter * 3 == i || quarter * 4 == i)
{
matdata.Add(new MatData(loadMat[i][0], Int32.Parse(loadMat[i][4])));
}
else
{
matdata.Add(new MatData(loadMat[i][0], Int32.Parse(loadMat[i][4])));
}
}
}
return matdata;
}
private List<MatData> loadSteel(List<string[]> loadMat)
{
List<MatData> matdata = new List<MatData>();
int lenth = loadMat.Count;
int quarter = lenth / 4;
for (int i = 0; i < loadMat.Count; i++ )
{
if (i == 0)
{
matdata.Add(new MatData(loadMat[i][0], Int32.Parse(loadMat[i][3])));
}
else
{
if (quarter == i || quarter * 2 == i || quarter * 3 == i || quarter * 4 == i)
{
matdata.Add(new MatData(loadMat[i][0], Int32.Parse(loadMat[i][3])));
}
else
{
matdata.Add(new MatData(loadMat[i][0], Int32.Parse(loadMat[i][3])));
}
}
}
return matdata;
}
private List<MatData> loadAmmo(List<string[]> loadMat)
{
List<MatData> matdata = new List<MatData>();
int lenth = loadMat.Count;
int quarter = lenth / 4;
for (int i = 0; i < loadMat.Count; i++)
{
if (i == 0)
{
matdata.Add(new MatData(loadMat[i][0], Int32.Parse(loadMat[i][2])));
}
else
{
if (quarter == i || quarter * 2 == i || quarter * 3 == i || quarter * 4 == i)
{
matdata.Add(new MatData(loadMat[i][0], Int32.Parse(loadMat[i][2])));
}
else
{
matdata.Add(new MatData(loadMat[i][0], Int32.Parse(loadMat[i][2])));
}
}
}
return matdata;
}
private List<MatData> loadFuel(List<string[]> loadMat)
{
List<MatData> matdata = new List<MatData>();
int lenth = loadMat.Count;
int quarter = lenth / 4;
for (int i = 0; i < loadMat.Count; i++)
{
if (i == 0)
{
matdata.Add(new MatData(loadMat[i][0], Int32.Parse(loadMat[i][1])));
}
else
{
if (quarter == i || quarter * 2 == i || quarter * 3 == i || quarter * 4 == i)
{
matdata.Add(new MatData(loadMat[i][0], Int32.Parse(loadMat[i][1])));
}
else
{
matdata.Add(new MatData(loadMat[i][0], Int32.Parse(loadMat[i][1])));
}
}
}
return matdata;
}
public static List<String[]> ReadCSV(string filePathName )
{
List<String[]> ls = new List<String[]>();
StreamReader fileReader = new StreamReader(filePathName);
string strLine = "";
fileReader.ReadLine(); //Skip first row.
while (strLine != null)
{
strLine = fileReader.ReadLine();
if (strLine != null && strLine.Length > 0)
{
ls.Add(strLine.Split(','));
}
}
fileReader.Close();
return ls;
}
}
public class MatData
{
public string DateOF { get; set; }
public int countOfMat { get; set; }
public MatData(string dateof, int countofmat)
{
DateOF = dateof;
countOfMat = countofmat;
}
}
}