回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,201 +1,99 @@
|
|
1
1
|
Chartコントロールは使ったことがないので何か間違いがあるかもしれませんが、それっぽく表示されているように思います。
|
2
|
-
|
3
2
|

|
4
|
-
|
5
|
-
[CustomLabel](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.forms.datavisualization.charting.customlabel) クラスの使い方がよくわかっていませんが、ラベルの値が中央に来るように`fromPosition`
|
3
|
+
[CustomLabel](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.forms.datavisualization.charting.customlabel) クラスの使い方がよくわかっていませんが、ラベルの値が中央に来るように`fromPosition`・`toPosition`を選択すればいいみたいです。
|
6
|
-
|
7
|
-
|
8
4
|
|
9
5
|
* 2を表示したい場合
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
`new CustomLabel(1.9, 2.1, "2",`でも`new CustomLabel(1, 3, "2",`でも、中央値が2になればなんでもいいみたいです
|
6
|
+
`new CustomLabel(1.9, 2.1, "2",`でも`new CustomLabel(1, 3, "2",`でも、中央値が2になればなんでもいいみたいです(しかし`new CustomLabel(2, 2, "2",`はダメです)
|
14
|
-
|
15
|
-
しかし`new CustomLabel(2, 2, "2",`はダメみたいです。
|
16
|
-
|
17
|
-
|
18
7
|
|
19
8
|
`GridTickTypes.All`にすると普通のグリッド線のようになります。
|
20
|
-
|
21
9
|
`LabelMarkStyle`はよくわかりません。
|
22
10
|
|
23
|
-
|
24
|
-
|
25
|
-
```
|
11
|
+
```cs
|
26
|
-
|
27
12
|
using System;
|
28
|
-
|
29
13
|
using System.IO;
|
30
|
-
|
31
14
|
using System.Text;
|
32
|
-
|
33
15
|
using System.Windows.Forms;
|
34
|
-
|
35
16
|
using System.Windows.Forms.DataVisualization.Charting;
|
36
17
|
|
37
|
-
|
38
|
-
|
39
18
|
namespace Questions236057
|
40
|
-
|
41
19
|
{
|
42
|
-
|
43
20
|
public partial class Form1 : Form
|
44
|
-
|
45
21
|
{
|
46
|
-
|
47
22
|
public Form1()
|
48
|
-
|
49
23
|
{
|
50
|
-
|
51
24
|
InitializeComponent();
|
52
|
-
|
53
25
|
Dammy();
|
54
|
-
|
55
26
|
}
|
56
27
|
|
57
|
-
|
58
|
-
|
59
28
|
private void button1_Click(object sender, EventArgs e)
|
60
|
-
|
61
29
|
{
|
62
|
-
|
63
30
|
chart1.Series.Clear();
|
64
|
-
|
65
31
|
chart1.Legends.Clear();
|
66
|
-
|
67
32
|
chart1.ChartAreas.Clear();
|
68
|
-
|
69
33
|
//chart1.Hide();
|
70
|
-
|
71
|
-
|
72
34
|
|
73
35
|
chart1.ChartAreas.Add(new ChartArea("1"));
|
74
36
|
|
75
|
-
|
76
|
-
|
77
37
|
chart1.ChartAreas[0].AxisX.Minimum = DateTime.MinValue.AddHours(8).ToOADate();
|
78
|
-
|
79
38
|
chart1.ChartAreas[0].AxisX.Maximum = DateTime.MinValue.AddHours(17).ToOADate();
|
80
|
-
|
81
39
|
chart1.ChartAreas[0].AxisX.Interval = 1;
|
82
|
-
|
83
40
|
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Hours;
|
84
|
-
|
85
41
|
chart1.ChartAreas[0].AxisX.IntervalOffsetType = DateTimeIntervalType.Hours;
|
86
|
-
|
87
42
|
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss";
|
88
43
|
|
89
|
-
|
90
|
-
|
91
44
|
chart1.ChartAreas[0].AxisY.Maximum = 3;
|
92
|
-
|
93
45
|
chart1.ChartAreas[0].AxisY.Minimum = 1;
|
94
|
-
|
95
46
|
chart1.ChartAreas[0].AxisY.CustomLabels.Add(new CustomLabel(0.9, 1.1, "1", 0, LabelMarkStyle.None, GridTickTypes.All));
|
96
|
-
|
97
47
|
chart1.ChartAreas[0].AxisY.CustomLabels.Add(new CustomLabel(1.1, 1.3, "1.2", 0, LabelMarkStyle.None, GridTickTypes.All));
|
98
|
-
|
99
48
|
chart1.ChartAreas[0].AxisY.CustomLabels.Add(new CustomLabel(1.9, 2.1, "2", 0, LabelMarkStyle.None, GridTickTypes.All));
|
100
|
-
|
101
49
|
chart1.ChartAreas[0].AxisY.CustomLabels.Add(new CustomLabel(2.6, 2.8, "2.7", 0, LabelMarkStyle.None, GridTickTypes.All));
|
102
|
-
|
103
50
|
chart1.ChartAreas[0].AxisY.CustomLabels.Add(new CustomLabel(2.9, 3.1, "3", 0, LabelMarkStyle.None, GridTickTypes.All));
|
104
51
|
|
105
|
-
|
106
|
-
|
107
52
|
//位置があってるか検証用コード
|
108
|
-
|
109
53
|
//chart1.ChartAreas[0].AxisY2.Maximum = 3;
|
110
|
-
|
111
54
|
//chart1.ChartAreas[0].AxisY2.Minimum = 1;
|
112
|
-
|
113
55
|
//chart1.ChartAreas[0].AxisY2.Interval = 0.1;
|
114
|
-
|
115
56
|
//chart1.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True;
|
116
57
|
|
117
58
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
59
|
var series1 = new Series
|
122
|
-
|
123
60
|
{
|
124
|
-
|
125
61
|
ChartArea = "1",
|
126
|
-
|
127
62
|
ChartType = SeriesChartType.Line,
|
128
|
-
|
129
63
|
XValueType = ChartValueType.Time,
|
130
|
-
|
131
64
|
IsVisibleInLegend = false,
|
132
|
-
|
133
65
|
IsValueShownAsLabel = false,
|
134
|
-
|
135
66
|
};
|
136
|
-
|
137
67
|
chart1.Series.Add(series1);
|
138
68
|
|
69
|
+
var list = File.ReadAllLines("test.tsv");
|
70
|
+
foreach(var line in list)
|
71
|
+
{
|
72
|
+
var xValue = DateTime.Parse("0001/01/01 " + line.Split('\t')[0]);
|
73
|
+
var yValue = line.Split('\t')[1];
|
74
|
+
var dp = new DataPoint();
|
75
|
+
dp.SetValueXY(xValue, yValue);
|
76
|
+
dp.IsValueShownAsLabel = false;
|
77
|
+
chart1.Series[0].Points.Add(dp);
|
78
|
+
}
|
79
|
+
}
|
139
80
|
|
140
|
-
|
81
|
+
private void Dammy()
|
82
|
+
{
|
83
|
+
var r = new Random();
|
84
|
+
var sb = new StringBuilder();
|
141
|
-
var
|
85
|
+
var d = DateTime.MinValue.AddHours(8);
|
142
|
-
|
143
|
-
|
86
|
+
while(true)
|
144
|
-
|
145
87
|
{
|
146
|
-
|
147
|
-
|
88
|
+
d += TimeSpan.FromSeconds(r.Next(60, 600));
|
148
|
-
|
89
|
+
if(17 <= d.Hour) break;
|
149
|
-
|
90
|
+
sb.Append(d.ToString("HH:mm:ss"));
|
150
|
-
|
151
|
-
|
91
|
+
sb.Append("\t");
|
152
|
-
|
153
|
-
dp.SetValueXY(xValue, yValue);
|
154
|
-
|
155
|
-
dp.IsValueShownAsLabel = false;
|
156
|
-
|
157
|
-
|
92
|
+
sb.AppendLine((r.NextDouble() + 1.5).ToString("0.00"));
|
158
|
-
|
159
93
|
}
|
160
94
|
|
95
|
+
File.WriteAllText("test.tsv", sb.ToString());
|
161
96
|
}
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
private void Dammy()
|
166
|
-
|
167
|
-
{
|
168
|
-
|
169
|
-
var r = new Random();
|
170
|
-
|
171
|
-
var sb = new StringBuilder();
|
172
|
-
|
173
|
-
var d = DateTime.MinValue.AddHours(8);
|
174
|
-
|
175
|
-
while(true)
|
176
|
-
|
177
|
-
{
|
178
|
-
|
179
|
-
d += TimeSpan.FromSeconds(r.Next(60, 600));
|
180
|
-
|
181
|
-
if(17 <= d.Hour) break;
|
182
|
-
|
183
|
-
sb.Append(d.ToString("HH:mm:ss"));
|
184
|
-
|
185
|
-
sb.Append("\t");
|
186
|
-
|
187
|
-
sb.AppendLine((r.NextDouble() + 1.5).ToString("0.00"));
|
188
|
-
|
189
|
-
}
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
File.WriteAllText("test.tsv", sb.ToString());
|
194
|
-
|
195
|
-
}
|
196
|
-
|
197
97
|
}
|
198
|
-
|
199
98
|
}
|
200
|
-
|
201
99
|
```
|