2013-07-29 122 views
3

我正在使用MSCharts,並且正在使用軸的日期,並且忍不住注意到軸標籤對於最後一個網格線是隱藏的。下圖顯示了這一點。MSCharts最後一軸標籤隱藏

Broken Chart Axis

,我使用這個代碼是:

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 

有誰知道爲什麼這些標籤是隱藏什麼想法?根據代碼,網格線位於正確的位置(每3個月),但軸標籤根本不顯示,而實際上這是修改此代碼的唯一位置

回答

4

LabelStyle.IsEndLabelVisible控制是否第一個和最後一個標籤被顯示。

Here is the MSDN entry.

我猜測,在代碼的某個地方,你沒有張貼是沿着這些路線的東西:

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

你要改變,要真正或完全是因爲將其刪除它默認爲true。

+0

真棒,這真的很好,非常感謝這麼多! –