MS 图表显示自定义标签并隐藏轴标签
本文关键字:标签 隐藏 自定义 显示 MS | 更新日期: 2023-09-27 18:35:30
我正在Visual Studio 2008(C#)中构建一个 ASP.NET 图表(System.Web.UI.DataVisualization.Charting.Chart),X轴上有自定义标签。我想隐藏自动生成的轴标签,只显示我的自定义标签。最好的方法是什么?
如果我设置 Axis 属性 LabelStyle.Enabled = false,那么我的自定义标签也会被隐藏。
更新:通过将 IntervalOffset 属性设置为 1000,它将自动标签移出图表。但是,现在图表底部和自定义标签之间存在差距。
找到答案:将我的自定义标签的 RowIndex 设置为 0。现在事情排好了。
我已经使用自定义标签和标签列表解决了这个问题。我有两个功能:一个添加自定义标签列表,另一个删除自定义标签列表。
/// <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);
}
}
}
您可以使用
系列。标签前色 = 颜色.透明