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

|
3
|
-
[CustomLabel](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.forms.datavisualization.charting.customlabel) クラスの使い方がよくわかっていませんが、ラベルの値が中央に来るように`fromPosition`
|
4
|
-
|
5
|
-
* 2を表示したい場合
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
`
|
12
|
-
|
13
|
-
|
14
|
-
using System;
|
15
|
-
using System.
|
16
|
-
using System.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
{
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
chart1.
|
33
|
-
chart1.
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
chart1.ChartAreas.
|
38
|
-
|
39
|
-
chart1.ChartAreas[0].AxisX.
|
40
|
-
chart1.ChartAreas[0].AxisX.
|
41
|
-
chart1.ChartAreas[0].AxisX.
|
42
|
-
chart1.ChartAreas[0].AxisX.
|
43
|
-
|
44
|
-
chart1.ChartAreas[0].
|
45
|
-
|
46
|
-
chart1.ChartAreas[0].AxisY.
|
47
|
-
chart1.ChartAreas[0].AxisY.
|
48
|
-
chart1.ChartAreas[0].AxisY.CustomLabels.Add(new CustomLabel(
|
49
|
-
chart1.ChartAreas[0].AxisY.CustomLabels.Add(new CustomLabel(
|
50
|
-
chart1.ChartAreas[0].AxisY.CustomLabels.Add(new CustomLabel(
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
//
|
55
|
-
//chart1.ChartAreas[0].AxisY2.
|
56
|
-
//chart1.ChartAreas[0].AxisY2.
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
var
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
var
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
sb.
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
}
|
100
|
-
}
|
1
|
+
Chartコントロールは使ったことがないので何か間違いがあるかもしれませんが、それっぽく表示されているように思います。
|
2
|
+

|
3
|
+
[CustomLabel](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.forms.datavisualization.charting.customlabel) クラスの使い方がよくわかっていませんが、ラベルの値が中央に来るように`fromPosition`・`toPosition`を選択すればいいみたいです。
|
4
|
+
|
5
|
+
* 2を表示したい場合
|
6
|
+
`new CustomLabel(1.9, 2.1, "2",`でも`new CustomLabel(1, 3, "2",`でも、中央値が2になればなんでもいいみたいです(しかし`new CustomLabel(2, 2, "2",`はダメです)
|
7
|
+
|
8
|
+
`GridTickTypes.All`にすると普通のグリッド線のようになります。
|
9
|
+
`LabelMarkStyle`はよくわかりません。
|
10
|
+
|
11
|
+
```cs
|
12
|
+
using System;
|
13
|
+
using System.IO;
|
14
|
+
using System.Text;
|
15
|
+
using System.Windows.Forms;
|
16
|
+
using System.Windows.Forms.DataVisualization.Charting;
|
17
|
+
|
18
|
+
namespace Questions236057
|
19
|
+
{
|
20
|
+
public partial class Form1 : Form
|
21
|
+
{
|
22
|
+
public Form1()
|
23
|
+
{
|
24
|
+
InitializeComponent();
|
25
|
+
Dammy();
|
26
|
+
}
|
27
|
+
|
28
|
+
private void button1_Click(object sender, EventArgs e)
|
29
|
+
{
|
30
|
+
chart1.Series.Clear();
|
31
|
+
chart1.Legends.Clear();
|
32
|
+
chart1.ChartAreas.Clear();
|
33
|
+
//chart1.Hide();
|
34
|
+
|
35
|
+
chart1.ChartAreas.Add(new ChartArea("1"));
|
36
|
+
|
37
|
+
chart1.ChartAreas[0].AxisX.Minimum = DateTime.MinValue.AddHours(8).ToOADate();
|
38
|
+
chart1.ChartAreas[0].AxisX.Maximum = DateTime.MinValue.AddHours(17).ToOADate();
|
39
|
+
chart1.ChartAreas[0].AxisX.Interval = 1;
|
40
|
+
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Hours;
|
41
|
+
chart1.ChartAreas[0].AxisX.IntervalOffsetType = DateTimeIntervalType.Hours;
|
42
|
+
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss";
|
43
|
+
|
44
|
+
chart1.ChartAreas[0].AxisY.Maximum = 3;
|
45
|
+
chart1.ChartAreas[0].AxisY.Minimum = 1;
|
46
|
+
chart1.ChartAreas[0].AxisY.CustomLabels.Add(new CustomLabel(0.9, 1.1, "1", 0, LabelMarkStyle.None, GridTickTypes.All));
|
47
|
+
chart1.ChartAreas[0].AxisY.CustomLabels.Add(new CustomLabel(1.1, 1.3, "1.2", 0, LabelMarkStyle.None, GridTickTypes.All));
|
48
|
+
chart1.ChartAreas[0].AxisY.CustomLabels.Add(new CustomLabel(1.9, 2.1, "2", 0, LabelMarkStyle.None, GridTickTypes.All));
|
49
|
+
chart1.ChartAreas[0].AxisY.CustomLabels.Add(new CustomLabel(2.6, 2.8, "2.7", 0, LabelMarkStyle.None, GridTickTypes.All));
|
50
|
+
chart1.ChartAreas[0].AxisY.CustomLabels.Add(new CustomLabel(2.9, 3.1, "3", 0, LabelMarkStyle.None, GridTickTypes.All));
|
51
|
+
|
52
|
+
//位置があってるか検証用コード
|
53
|
+
//chart1.ChartAreas[0].AxisY2.Maximum = 3;
|
54
|
+
//chart1.ChartAreas[0].AxisY2.Minimum = 1;
|
55
|
+
//chart1.ChartAreas[0].AxisY2.Interval = 0.1;
|
56
|
+
//chart1.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True;
|
57
|
+
|
58
|
+
|
59
|
+
var series1 = new Series
|
60
|
+
{
|
61
|
+
ChartArea = "1",
|
62
|
+
ChartType = SeriesChartType.Line,
|
63
|
+
XValueType = ChartValueType.Time,
|
64
|
+
IsVisibleInLegend = false,
|
65
|
+
IsValueShownAsLabel = false,
|
66
|
+
};
|
67
|
+
chart1.Series.Add(series1);
|
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
|
+
}
|
80
|
+
|
81
|
+
private void Dammy()
|
82
|
+
{
|
83
|
+
var r = new Random();
|
84
|
+
var sb = new StringBuilder();
|
85
|
+
var d = DateTime.MinValue.AddHours(8);
|
86
|
+
while(true)
|
87
|
+
{
|
88
|
+
d += TimeSpan.FromSeconds(r.Next(60, 600));
|
89
|
+
if(17 <= d.Hour) break;
|
90
|
+
sb.Append(d.ToString("HH:mm:ss"));
|
91
|
+
sb.Append("\t");
|
92
|
+
sb.AppendLine((r.NextDouble() + 1.5).ToString("0.00"));
|
93
|
+
}
|
94
|
+
|
95
|
+
File.WriteAllText("test.tsv", sb.ToString());
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
101
99
|
```
|