C# 图表自定义标签不显示在X轴上

C# 图表自定义标签不显示在X轴上,c#,charts,C#,Charts,我已经尝试了发布的几个解决方案,但似乎都不起作用 salesTitle.Text = chartTitle; this.chtSales.Series.Clear(); this.chtSales.Titles.Add(salesTitle); this.chtSales.ChartAreas[0].AxisX.Interval = 1; // Try for Custom Labels foreach (string monthName in monthArray) { string

我已经尝试了发布的几个解决方案,但似乎都不起作用

salesTitle.Text = chartTitle;
this.chtSales.Series.Clear();
this.chtSales.Titles.Add(salesTitle);
this.chtSales.ChartAreas[0].AxisX.Interval = 1;

// Try for Custom Labels
foreach (string monthName in monthArray)
{
    string sMonthName = monthName;
    sMonthName = char.ToUpper(sMonthName[0]) + sMonthName.Substring(1);
    CustomLabel monthLabel = new CustomLabel();
    monthLabel.Text = sMonthName;
    this.chtSales.ChartAreas[0].AxisX.CustomLabels.Add(monthLabel);
}
我想我可能需要在
CustomLabel
函数调用中添加一些参数,但我无法确定它们应该是什么


好的一面是数据显示正确。

感谢Rufus的链接,确实需要设置FromPosition和ToPosition。对于其他与同一问题作斗争的人,下面的代码是有效的,尽管我正在将月份名称添加到x轴

// Try for Custom Labels
for(int i = 0; i < monthArray.Length; i++)
{
   string sMonthName = monthArray[i];
   sMonthName = char.ToUpper(sMonthName[0]) + sMonthName.Substring(1);
   CustomLabel lblMonth = new CustomLabel();
   lblMonth.FromPosition = i;
   lblMonth.ToPosition = i + 1;
   lblMonth.Text = sMonthName;
   this.chtAccum.ChartAreas[0].AxisX.CustomLabels.Add(lblMonth);
}
//尝试自定义标签
对于(int i=0;i
您需要将FromPosition和ToPosition设置为合适的值。-另外:您的x值需要是数字(或日期)。。