[英]MS Chart show custom labels and hide axis labels
我正在Visual Studio 2008(C#)中使用X軸上的自定義標簽構建ASP.NET圖表(System.Web.UI.DataVisualization.Charting.Chart)。 我想隱藏自動生成的軸標簽,只顯示我的自定義標簽。 做這個的最好方式是什么?
如果我將Axis屬性設置為LabelStyle.Enabled = false,那么我的自定義標簽也將被隱藏。
更新:通過將IntervalOffset屬性設置為1000,它將自動標簽移出圖表。 但是,現在圖表底部和自定義標簽之間有一個縫隙。
找到了答案:將“自定義標簽”的RowIndex設置為0。 現在事情就好了。
我已經使用了customlabel和tag列表解決了這個問題。 我有兩個功能:一個添加customlabel列表,另一個刪除customlabel列表。
/// <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);
}
}
}
您可以使用
series.LabelForeColor = Color.Transparent
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.