MS Chart显示自定义标签和隐藏轴标签

问题描述 投票:0回答:3

我正在Visual Studio 2008(C#)中使用X轴上的自定义标签构建ASP.NET图表(System.Web.UI.DataVisualization.Charting.Chart)。我想隐藏自动生成的轴标签,只显示我的自定义标签。做这个的最好方式是什么?

如果我设置Axis属性LabelStyle.Enabled = false,那么我的自定义标签也会被隐藏。

更新:通过将IntervalOffset属性设置为1000,它会将自动标签移出图表。但是,图表底部与自定义标签之间现在存在差距。

c# charts
3个回答
1
投票

找到答案:为我的自定义标签设置RowIndex为0。现在事情就好了。


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);
            }
        }
     }

0
投票

您可以使用

series.LabelForeColor = Color.Transparent

© www.soinside.com 2019 - 2024. All rights reserved.