【问题标题】:MS Chart show custom labels and hide axis labelsMS Chart 显示自定义标签和隐藏轴标签
【发布时间】:2013-10-15 11:45:38
【问题描述】:

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

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

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

【问题讨论】:

  • 请向我们展示您的代码

标签: c# charts


【解决方案1】:

找到答案:将我的自定义标签的 RowIndex 设置为 0。现在一切都很好。

【讨论】:

    【解决方案2】:

    我已经使用自定义标签和标签列表解决了这个问题。我有两个功能:一个添加自定义标签列表,一个删除自定义标签列表。

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

    【讨论】:

      【解决方案3】:

      你可以使用

      series.LabelForeColor = Color.Transparent

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-09
        • 2011-05-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多