[英]Chart custom labels not appearing on X axis
我已經嘗試了幾個發布的解決方案,但它們似乎都不起作用。
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 AXIS,但下面的代碼仍然有效。
// 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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.