2013-10-15 288 views
0

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

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

UPDATE:由IntervalOffset属性设置为1000时,它移动的自动标签断图表。但是,图表底部和自定义标签之间现在存在差距。

+0

请告诉我们你的代码 – Rohit

回答

1

找到了答案:设置的rowIndex为0我的自定义标签。现在事情排队很好。

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