質問編集履歴
1
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -54,4 +54,210 @@
|
|
54
54
|
|
55
55
|
|
56
56
|
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
57
61
|
Visual Studio 2017 .NET Framework 4.6.1
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
コード追記しました。汚いコードですが、よろしくお願いいたします。
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
### 該当のソースコード
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
```c#
|
74
|
+
|
75
|
+
public partial class Form1 : Form
|
76
|
+
|
77
|
+
{
|
78
|
+
|
79
|
+
private string[] files = Directory.GetFiles(@"Path", "*.csv");
|
80
|
+
|
81
|
+
private int j = 0;
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
public Form1()
|
86
|
+
|
87
|
+
{
|
88
|
+
|
89
|
+
InitializeComponent();
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
timer1.Interval = 1000;
|
94
|
+
|
95
|
+
timer1.Enabled = true;
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
public void Graph()
|
100
|
+
|
101
|
+
{
|
102
|
+
|
103
|
+
//最初あるチャートのクリア
|
104
|
+
|
105
|
+
chart1.Series.Clear();
|
106
|
+
|
107
|
+
chart1.ChartAreas.Clear();
|
108
|
+
|
109
|
+
chart1.Titles.Clear();
|
110
|
+
|
111
|
+
// プロットの設定
|
112
|
+
|
113
|
+
Series Series1 = new Series
|
114
|
+
|
115
|
+
{
|
116
|
+
|
117
|
+
ChartType = SeriesChartType.FastLine,
|
118
|
+
|
119
|
+
BorderWidth = 2,
|
120
|
+
|
121
|
+
MarkerStyle = MarkerStyle.Circle,
|
122
|
+
|
123
|
+
MarkerSize = 2
|
124
|
+
|
125
|
+
};
|
126
|
+
|
127
|
+
// データセット
|
128
|
+
|
129
|
+
for (int i = 0; i < Data(files[j]).Length; i=i+5)
|
130
|
+
|
131
|
+
{
|
132
|
+
|
133
|
+
DataPoint dp = new DataPoint(double.Parse(Data(files[j])[i][1]), double.Parse(Data(files[j])[i][0]));
|
134
|
+
|
135
|
+
Series1.Points.Add(dp);
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
// X軸、Y軸のラベル設定
|
140
|
+
|
141
|
+
ChartArea ChartArea1 = new ChartArea();
|
142
|
+
|
143
|
+
ChartArea1.AxisX.Title = "x軸のタイトル";
|
144
|
+
|
145
|
+
ChartArea1.AxisY.Title = "y軸のタイトル";
|
146
|
+
|
147
|
+
ChartArea1.AxisY.IsReversed = true;
|
148
|
+
|
149
|
+
ChartArea1.AxisX.TitleForeColor = Color.Black;
|
150
|
+
|
151
|
+
// チャートに各設定項目追加
|
152
|
+
|
153
|
+
chart1.Titles.Add(title);
|
154
|
+
|
155
|
+
chart1.ChartAreas.Add(ChartArea1);
|
156
|
+
|
157
|
+
chart1.Series.Add(Series1);
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
chart1.Series[0].IsVisibleInLegend = false; //凡例を非表示
|
162
|
+
|
163
|
+
chart1.Series[0].Color = Color.Black; //線色を設定
|
164
|
+
|
165
|
+
// グラフ枠線設定
|
166
|
+
|
167
|
+
chart1.ChartAreas[0].BorderColor = Color.Black;
|
168
|
+
|
169
|
+
chart1.ChartAreas[0].BorderDashStyle = ChartDashStyle.Solid;
|
170
|
+
|
171
|
+
chart1.ChartAreas[0].BorderWidth = 2;
|
172
|
+
|
173
|
+
// Y軸設定
|
174
|
+
|
175
|
+
chart1.ChartAreas[0].AxisY.Minimum = 0;
|
176
|
+
|
177
|
+
chart1.ChartAreas[0].AxisY.Maximum = 35;
|
178
|
+
|
179
|
+
chart1.ChartAreas[0].AxisY.Interval = 5;
|
180
|
+
|
181
|
+
chart1.ChartAreas[0].AxisY.MajorTickMark.LineWidth = 0;
|
182
|
+
|
183
|
+
chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.DarkGray;
|
184
|
+
|
185
|
+
// X軸設定
|
186
|
+
|
187
|
+
chart1.ChartAreas[0].AxisX.Minimum = 0;
|
188
|
+
|
189
|
+
chart1.ChartAreas[0].AxisX.Maximum = 20;
|
190
|
+
|
191
|
+
chart1.ChartAreas[0].AxisX.Interval = 5;
|
192
|
+
|
193
|
+
chart1.ChartAreas[0].AxisX.MajorTickMark.LineWidth = 0;
|
194
|
+
|
195
|
+
chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.DarkGray;
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
public string[][] Data(string file)
|
200
|
+
|
201
|
+
{
|
202
|
+
|
203
|
+
char[] linedelimiter = { '\n' };
|
204
|
+
|
205
|
+
char[] columndelimiter = { ' ' };
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
List<string[]> readCsvList = new List<string[]>();
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
using (StreamReader Sr = new StreamReader(file, Encoding.UTF8))
|
214
|
+
|
215
|
+
{
|
216
|
+
|
217
|
+
Sr.ReadLine(); //ヘッダ読み飛ばし
|
218
|
+
|
219
|
+
Sr.ReadLine(); //ヘッダ2個目読み飛ばし
|
220
|
+
|
221
|
+
while (!Sr.EndOfStream)
|
222
|
+
|
223
|
+
{
|
224
|
+
|
225
|
+
string[] readCsvLine = Sr.ReadToEnd().Trim().Split(linedelimiter, StringSplitOptions.RemoveEmptyEntries);
|
226
|
+
|
227
|
+
foreach (string readCsvColumn in readCsvLine)
|
228
|
+
|
229
|
+
{
|
230
|
+
|
231
|
+
string[] DataItem = readCsvColumn.Trim().Split(columndelimiter, StringSplitOptions.RemoveEmptyEntries);
|
232
|
+
|
233
|
+
if (DataItem.Length == 10)
|
234
|
+
|
235
|
+
{
|
236
|
+
|
237
|
+
readCsvList.Add(DataItem);
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
return readCsvList.ToArray();
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
private void timer1_Tick(object sender, EventArgs e)
|
252
|
+
|
253
|
+
{
|
254
|
+
|
255
|
+
Graph();
|
256
|
+
|
257
|
+
j++;
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
```
|