タイトル | : Re: ChartのX軸の日付や時刻の表示を任意に指定。 |
記事No | : 11711 |
投稿日 | : 2016/08/09(Tue) 05:05 |
投稿者 | : shu |
カスタムラベルを使うと出来ます。 位置調整が少し難しいです。
Private _tbl As DataTable Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load _tbl = New DataTable() With _tbl.Columns .Add("x", GetType(Date)) .Add("y", GetType(Integer)) End With
Dim rnd As New Random() For Each dy In Enumerable.Range(1, 31) _tbl.Rows.Add(#8/1/2016#.AddDays(dy - 1), rnd.Next(0, 20)) Next
Chart1.DataSource = _tbl
With Chart1.Series(0) .ChartType = DataVisualization.Charting.SeriesChartType.Line .XAxisType = AxisType.Primary .XValueType = ChartValueType.Date .XValueMember = "x" .YValueMembers = "y" .IsXValueIndexed = True End With
Dim labelWidth = 2 '--- ラベル幅の半分程度 With Chart1.ChartAreas(0).AxisX With .CustomLabels.Add(1 - labelWidth, 1 + labelWidth, "8/1") .GridTicks = GridTickTypes.All End With With .CustomLabels.Add(10 - labelWidth, 10 + labelWidth, "8/10") .GridTicks = GridTickTypes.All End With With .CustomLabels.Add(20 - labelWidth, 20 + labelWidth, "8/20") .GridTicks = GridTickTypes.All End With .LabelStyle.Font = New Font("MS P明朝", 10) .MajorGrid.Enabled = True .LabelStyle.TruncatedLabels = False .LabelAutoFitStyle = LabelAutoFitStyles.DecreaseFont Or LabelAutoFitStyles.IncreaseFont .LabelAutoFitMaxFontSize = 20 .LabelAutoFitMinFontSize = 5 .LabelStyle.Interval = 1 End With
End Sub
|