我已經解決了使用自定義標籤和標籤列表的問題。我有兩個功能:一個添加自定義標籤列表和一個刪除自定義標籤列表的功能。
/// <summary>
/// Add a list of CustomLabel to X Axis
/// </summary>
/// <param name="customLabelList">List of custom label</param>
/// <param name="chartArea">Destination ChartArea</param>
/// <param name="tag">Tag tha unique identify the custom label list</param>
/// <param name="rowIndex"></param>
public void AddAxisXCustomLabel(List<CustomLabel> customLabelList, string chartArea, string tag,int rowIndex)
{
foreach (CustomLabel cl in customLabelList)
{
cl.RowIndex = rowIndex;
cl.Tag = tag;
chart.ChartAreas[chartArea].AxisX.CustomLabels.Add(cl);
}
}
/// <summary>
/// Remove custom label from a list of custom label
/// </summary>
/// <param name="chartArea">Destination ChartArea</param>
/// <param name="tag">Tag tha unique identify the custom label list</param>
public void RemoveCustomLabelByTag(string chartArea,string tag)
{
for (int i = (chart.ChartAreas[chartArea].AxisX.CustomLabels.Count-1); i > -1; --i)
{
CustomLabel cl = chart.ChartAreas[chartArea].AxisX.CustomLabels[i];
if (cl.Tag.Equals(tag))
{
chart.ChartAreas[chartArea].AxisX.CustomLabels.RemoveAt(i);
}
}
}
請告訴我們你的代碼 – Rohit