0
votes

I am building an ASP.NET Chart (System.Web.UI.DataVisualization.Charting.Chart) in Visual Studio 2008 (C#) with Custom Labels on the X axis. I want to hide the automatically generated axis labels and just show my custom labels. What is the best way to do this?

If I set the Axis property LabelStyle.Enabled = false then my custom labels are hidden as well.

UPDATE: By setting the IntervalOffset property to 1000, it moves the automatic labels off the chart. However, there is now a gap between the bottom of the chart and the custom labels.

3
please show us your codeRohit

3 Answers

1
votes

Found the answer: Set RowIndex to 0 for my Custom Labels. Now things line up just fine.

0
votes

I have solved the problem using a list of customlabel and tag. I have two function: one that add list of customlabel and one that remove a list of 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
votes

You can use

series.LabelForeColor = Color.Transparent