回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,213 +1,107 @@
|
|
1
1
|
> おそらく何かプロパティのような物が存在する
|
2
2
|
|
3
|
-
|
4
|
-
|
5
3
|
さすがにそこまではやってくれないんじゃないでしょうか?(ほとんど使ったことないのでわかりませんが)
|
6
|
-
|
7
4
|
元々が日付なわけですから`DateTime`にすればいいですね。
|
8
5
|
|
9
|
-
|
10
|
-
|
11
|
-
```
|
6
|
+
```cs
|
12
|
-
|
13
7
|
using System;
|
14
|
-
|
15
8
|
using System.Data;
|
16
|
-
|
17
9
|
using System.Globalization;
|
18
|
-
|
19
10
|
using System.Linq;
|
20
|
-
|
21
11
|
using System.Windows.Forms;
|
22
|
-
|
23
12
|
using System.Windows.Forms.DataVisualization.Charting;
|
24
13
|
|
25
|
-
|
26
|
-
|
27
14
|
namespace Questions244234
|
28
|
-
|
29
15
|
{
|
30
|
-
|
31
16
|
public partial class Form1 : Form
|
32
|
-
|
33
17
|
{
|
34
|
-
|
35
18
|
public Form1()
|
36
|
-
|
37
19
|
{
|
38
|
-
|
39
20
|
InitializeComponent();
|
40
21
|
|
41
|
-
|
42
|
-
|
43
22
|
var dt = Dammy();
|
44
|
-
|
45
23
|
test(dt);
|
46
|
-
|
47
24
|
dataGridView1.DataSource = dt;
|
48
|
-
|
49
25
|
}
|
50
26
|
|
51
|
-
|
52
|
-
|
53
27
|
private void test(DataTable dt)
|
54
|
-
|
55
28
|
{
|
56
|
-
|
57
29
|
// clear
|
58
|
-
|
59
30
|
chart1.Series.Clear();
|
60
|
-
|
61
31
|
chart1.ChartAreas.Clear();
|
62
|
-
|
63
32
|
chart1.Titles.Clear();
|
64
|
-
|
65
|
-
|
66
33
|
|
67
34
|
chart1.Titles.Add(new Title("Title1"));
|
68
35
|
|
69
|
-
|
70
|
-
|
71
36
|
// series
|
72
|
-
|
73
37
|
var seriesLine = new Series
|
74
|
-
|
75
38
|
{
|
76
|
-
|
77
39
|
ChartType = SeriesChartType.Line,
|
78
|
-
|
79
40
|
LegendText = "Legend:Line",
|
80
|
-
|
81
41
|
BorderWidth = 2,
|
82
|
-
|
83
42
|
MarkerStyle = MarkerStyle.Circle,
|
84
|
-
|
85
43
|
MarkerSize = 12
|
86
|
-
|
87
44
|
};
|
88
|
-
|
89
45
|
foreach(var item in dt.AsEnumerable())
|
90
|
-
|
91
46
|
{
|
92
|
-
|
93
47
|
// 平成25年(2013年)?を2025年としてしまうのが気にならなければ
|
94
|
-
|
95
48
|
// 単にこれでいい(chart1_FormatNumberはいらない)
|
96
|
-
|
97
49
|
//var date = DateTime.ParseExact((string)item.ItemArray[3], "yyMM", null);
|
98
|
-
|
99
50
|
var date = DateTime.ParseExact((string)item.ItemArray[3], "yyMM", null).AddYears(-12);
|
100
51
|
|
52
|
+
var dp = new DataPoint(date.ToOADate(), Convert.ToDouble(item.ItemArray[5]));
|
53
|
+
seriesLine.Points.Add(dp);
|
54
|
+
}
|
55
|
+
chart1.Series.Add(seriesLine);
|
101
56
|
|
57
|
+
// chartarea
|
58
|
+
var area1 = new ChartArea();
|
59
|
+
area1.AxisX.Title = "Title-XAxis";
|
60
|
+
area1.AxisY.Title = "Title-YAxis";
|
61
|
+
chart1.ChartAreas.Add(area1);
|
102
62
|
|
63
|
+
// AxisX
|
64
|
+
area1.AxisX.Interval = 12;
|
65
|
+
area1.AxisX.IntervalType = DateTimeIntervalType.Months;
|
103
|
-
|
66
|
+
area1.AxisX.IntervalOffsetType = DateTimeIntervalType.Months;
|
67
|
+
//area1.AxisX.LabelStyle.Format = "yyMM";
|
68
|
+
}
|
104
69
|
|
70
|
+
private void chart1_FormatNumber(object sender, FormatNumberEventArgs e)
|
71
|
+
{
|
105
|
-
|
72
|
+
if(e.ValueType == ChartValueType.DateTime)
|
73
|
+
{
|
74
|
+
var culture = new CultureInfo("ja-JP", true);
|
75
|
+
culture.DateTimeFormat.Calendar = new JapaneseCalendar();
|
106
76
|
|
77
|
+
var date = DateTime.FromOADate(e.Value);
|
78
|
+
e.LocalizedValue = date.ToString("yyMM", culture);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
private DataTable Dammy()
|
83
|
+
{
|
84
|
+
var dt = new DataTable();
|
85
|
+
dt.Columns.Add("AREA");
|
86
|
+
dt.Columns.Add("GENDER");
|
87
|
+
dt.Columns.Add("AGE");
|
88
|
+
dt.Columns.Add("MONTH");
|
89
|
+
dt.Columns.Add("DISEASE");
|
90
|
+
dt.Columns.Add("MED_1");
|
91
|
+
dt.Columns.Add("MED_2");
|
92
|
+
|
93
|
+
var r = new Random();
|
94
|
+
for(var i = 0; i < 48; i++)
|
95
|
+
{
|
96
|
+
var month = $"{25 + (i + 3) / 12}{(i + 3) % 12 + 1:00}";
|
97
|
+
var med_1 = r.Next(450_000, 550_000);
|
98
|
+
dt.Rows.Add("", "", "", month, "", med_1, "");
|
107
99
|
}
|
108
100
|
|
109
|
-
chart1.Series.Add(seriesLine);
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
// chartarea
|
114
|
-
|
115
|
-
var area1 = new ChartArea();
|
116
|
-
|
117
|
-
area1.AxisX.Title = "Title-XAxis";
|
118
|
-
|
119
|
-
area1.AxisY.Title = "Title-YAxis";
|
120
|
-
|
121
|
-
chart1.ChartAreas.Add(area1);
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
// AxisX
|
126
|
-
|
127
|
-
|
101
|
+
return dt;
|
128
|
-
|
129
|
-
area1.AxisX.IntervalType = DateTimeIntervalType.Months;
|
130
|
-
|
131
|
-
area1.AxisX.IntervalOffsetType = DateTimeIntervalType.Months;
|
132
|
-
|
133
|
-
//area1.AxisX.LabelStyle.Format = "yyMM";
|
134
|
-
|
135
102
|
}
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
private void chart1_FormatNumber(object sender, FormatNumberEventArgs e)
|
140
|
-
|
141
|
-
{
|
142
|
-
|
143
|
-
if(e.ValueType == ChartValueType.DateTime)
|
144
|
-
|
145
|
-
{
|
146
|
-
|
147
|
-
var culture = new CultureInfo("ja-JP", true);
|
148
|
-
|
149
|
-
culture.DateTimeFormat.Calendar = new JapaneseCalendar();
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
var date = DateTime.FromOADate(e.Value);
|
154
|
-
|
155
|
-
e.LocalizedValue = date.ToString("yyMM", culture);
|
156
|
-
|
157
|
-
}
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
private DataTable Dammy()
|
164
|
-
|
165
|
-
{
|
166
|
-
|
167
|
-
var dt = new DataTable();
|
168
|
-
|
169
|
-
dt.Columns.Add("AREA");
|
170
|
-
|
171
|
-
dt.Columns.Add("GENDER");
|
172
|
-
|
173
|
-
dt.Columns.Add("AGE");
|
174
|
-
|
175
|
-
dt.Columns.Add("MONTH");
|
176
|
-
|
177
|
-
dt.Columns.Add("DISEASE");
|
178
|
-
|
179
|
-
dt.Columns.Add("MED_1");
|
180
|
-
|
181
|
-
dt.Columns.Add("MED_2");
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
var r = new Random();
|
186
|
-
|
187
|
-
for(var i = 0; i < 48; i++)
|
188
|
-
|
189
|
-
{
|
190
|
-
|
191
|
-
var month = $"{25 + (i + 3) / 12}{(i + 3) % 12 + 1:00}";
|
192
|
-
|
193
|
-
var med_1 = r.Next(450_000, 550_000);
|
194
|
-
|
195
|
-
dt.Rows.Add("", "", "", month, "", med_1, "");
|
196
|
-
|
197
|
-
}
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
return dt;
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
103
|
}
|
206
|
-
|
207
104
|
}
|
208
|
-
|
209
105
|
```
|
210
106
|
|
211
|
-
|
212
|
-
|
213
107
|
![アプリ画像](1adf35792e000183d21712a5296e807e.png)
|