3

I'm using MSCharts and am using dates for the axes and couldn't help but notice that the axis label is hidden for the last grid line. The image below shows this.

Broken Chart Axis

The code that I am using for this is:

Public Function buildXAxis(ByVal chartArea As ChartArea, ByVal min As DateTime, ByVal max As DateTime) As Axis
        Dim xAxis As New Axis(chartArea, AxisName.X) 'Chart Area is passed into the function
        With xAxis
            .Interval = 3 'This is the interval, so the next visible label should be 7/1/2013
            .IntervalType = DateTimeIntervalType.Months 
            .IntervalAutoMode = IntervalAutoMode.FixedCount
            .Maximum = max.ToOADate 'In this instance, it is 7/29/2013
            .Minimum = min.ToOADate 'In this instance, it is 1/29/2013
            .TitleAlignment = Drawing.StringAlignment.Center
            .TitleForeColor = Drawing.Color.FromArgb(129, 127, 124)
            .TextOrientation = TextOrientation.Auto
            .LabelAutoFitStyle = LabelAutoFitStyles.LabelsAngleStep45
            Dim xLabelStyle As New LabelStyle
            xLabelStyle.TruncatedLabels = False
            xLabelStyle.IsStaggered = False
            xLabelStyle.Format = "d"
            .LabelStyle = xLabelStyle
            .MajorGrid.LineColor = Drawing.Color.FromArgb(129, 127, 124)
            .MinorGrid.LineColor = Drawing.Color.FromArgb(129, 127, 124)
            .MajorTickMark.LineColor = Drawing.Color.FromArgb(129, 127, 124)
            .MinorTickMark.LineColor = Drawing.Color.FromArgb(129, 127, 124)
        End With
        Return xAxis
    End Function

Does anybody have any idea why those labels are hidden? According to the code, the gridlines are in the right place, (Every 3 months) but the axis labels simply not showing, and this is in fact the only place modifying this code

4

1 回答 1

4

LabelStyle.IsEndLabelVisible 控制是否显示第一个和最后一个标签。

这是 MSDN 条目。

我猜你没有发布的代码中的某个地方是这样的:

Dim chartingArea As New ChartArea
chartingArea.AxisX.LabelStyle.IsEndLabelVisible = False

您需要将其更改为 true 或完全删除它,因为它默认为 true。

于 2013-07-29T21:25:00.600 回答