質問編集履歴
1
コード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -26,4 +26,107 @@
|
|
26
26
|
何の情報を入れればいいかわからなかったので、抽象的な質問になって、
|
27
27
|
申し訳ありませんが、よろしくお願いいたします。
|
28
28
|
|
29
|
+
|
30
|
+
|
29
|
-
Visual Studio 2017 .NET Framework 4.6.1
|
31
|
+
Visual Studio 2017 .NET Framework 4.6.1
|
32
|
+
|
33
|
+
コード追記しました。汚いコードですが、よろしくお願いいたします。
|
34
|
+
|
35
|
+
### 該当のソースコード
|
36
|
+
|
37
|
+
```c#
|
38
|
+
public partial class Form1 : Form
|
39
|
+
{
|
40
|
+
private string[] files = Directory.GetFiles(@"Path", "*.csv");
|
41
|
+
private int j = 0;
|
42
|
+
|
43
|
+
public Form1()
|
44
|
+
{
|
45
|
+
InitializeComponent();
|
46
|
+
|
47
|
+
timer1.Interval = 1000;
|
48
|
+
timer1.Enabled = true;
|
49
|
+
}
|
50
|
+
public void Graph()
|
51
|
+
{
|
52
|
+
//最初あるチャートのクリア
|
53
|
+
chart1.Series.Clear();
|
54
|
+
chart1.ChartAreas.Clear();
|
55
|
+
chart1.Titles.Clear();
|
56
|
+
// プロットの設定
|
57
|
+
Series Series1 = new Series
|
58
|
+
{
|
59
|
+
ChartType = SeriesChartType.FastLine,
|
60
|
+
BorderWidth = 2,
|
61
|
+
MarkerStyle = MarkerStyle.Circle,
|
62
|
+
MarkerSize = 2
|
63
|
+
};
|
64
|
+
// データセット
|
65
|
+
for (int i = 0; i < Data(files[j]).Length; i=i+5)
|
66
|
+
{
|
67
|
+
DataPoint dp = new DataPoint(double.Parse(Data(files[j])[i][1]), double.Parse(Data(files[j])[i][0]));
|
68
|
+
Series1.Points.Add(dp);
|
69
|
+
}
|
70
|
+
// X軸、Y軸のラベル設定
|
71
|
+
ChartArea ChartArea1 = new ChartArea();
|
72
|
+
ChartArea1.AxisX.Title = "x軸のタイトル";
|
73
|
+
ChartArea1.AxisY.Title = "y軸のタイトル";
|
74
|
+
ChartArea1.AxisY.IsReversed = true;
|
75
|
+
ChartArea1.AxisX.TitleForeColor = Color.Black;
|
76
|
+
// チャートに各設定項目追加
|
77
|
+
chart1.Titles.Add(title);
|
78
|
+
chart1.ChartAreas.Add(ChartArea1);
|
79
|
+
chart1.Series.Add(Series1);
|
80
|
+
|
81
|
+
chart1.Series[0].IsVisibleInLegend = false; //凡例を非表示
|
82
|
+
chart1.Series[0].Color = Color.Black; //線色を設定
|
83
|
+
// グラフ枠線設定
|
84
|
+
chart1.ChartAreas[0].BorderColor = Color.Black;
|
85
|
+
chart1.ChartAreas[0].BorderDashStyle = ChartDashStyle.Solid;
|
86
|
+
chart1.ChartAreas[0].BorderWidth = 2;
|
87
|
+
// Y軸設定
|
88
|
+
chart1.ChartAreas[0].AxisY.Minimum = 0;
|
89
|
+
chart1.ChartAreas[0].AxisY.Maximum = 35;
|
90
|
+
chart1.ChartAreas[0].AxisY.Interval = 5;
|
91
|
+
chart1.ChartAreas[0].AxisY.MajorTickMark.LineWidth = 0;
|
92
|
+
chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.DarkGray;
|
93
|
+
// X軸設定
|
94
|
+
chart1.ChartAreas[0].AxisX.Minimum = 0;
|
95
|
+
chart1.ChartAreas[0].AxisX.Maximum = 20;
|
96
|
+
chart1.ChartAreas[0].AxisX.Interval = 5;
|
97
|
+
chart1.ChartAreas[0].AxisX.MajorTickMark.LineWidth = 0;
|
98
|
+
chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.DarkGray;
|
99
|
+
}
|
100
|
+
public string[][] Data(string file)
|
101
|
+
{
|
102
|
+
char[] linedelimiter = { '\n' };
|
103
|
+
char[] columndelimiter = { ' ' };
|
104
|
+
|
105
|
+
List<string[]> readCsvList = new List<string[]>();
|
106
|
+
|
107
|
+
using (StreamReader Sr = new StreamReader(file, Encoding.UTF8))
|
108
|
+
{
|
109
|
+
Sr.ReadLine(); //ヘッダ読み飛ばし
|
110
|
+
Sr.ReadLine(); //ヘッダ2個目読み飛ばし
|
111
|
+
while (!Sr.EndOfStream)
|
112
|
+
{
|
113
|
+
string[] readCsvLine = Sr.ReadToEnd().Trim().Split(linedelimiter, StringSplitOptions.RemoveEmptyEntries);
|
114
|
+
foreach (string readCsvColumn in readCsvLine)
|
115
|
+
{
|
116
|
+
string[] DataItem = readCsvColumn.Trim().Split(columndelimiter, StringSplitOptions.RemoveEmptyEntries);
|
117
|
+
if (DataItem.Length == 10)
|
118
|
+
{
|
119
|
+
readCsvList.Add(DataItem);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
return readCsvList.ToArray();
|
125
|
+
}
|
126
|
+
private void timer1_Tick(object sender, EventArgs e)
|
127
|
+
{
|
128
|
+
Graph();
|
129
|
+
j++;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
```
|