如何隐藏折线图中数据点的标签

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

请参考下图。

基本上我有一个 C# 图表控件,上面有一些系列,我有一个带有标签的系列(图中的红线),但我希望能够打开/关闭标签。那可能吗?我找不到任何可以这样做的属性。

非常感谢。

c# mschart linechart
2个回答
2
投票

除了清除

labels
的文本之外,一种简单的方法就是使颜色透明。

你可以做整个

Series s1
:

s1.LabelForeColor = checkBox_test.Checked ? Color.Black: Color.Transparent;

..或个人

DataPoints dp
:

dp.LabelForeColor = checkBox_test.Checked ? Color.Blue : Color.Transparent;

0
投票

另一种解决方案是将标签存储到点的自定义属性中,并在打开标签时将值分配给DataPoint.Label

/* Store the labels to the custom properties on initialization. */
series.Points[index].SetCustomProperty("Label", "My label");

/* .... */
if (checkboxLabels.Checked) 
{
    /* If the labels are toggled on, initialize the Label property. */
    var label = series.Points[index].GetCustomProperty("Label");
    if (!string.IsNullOrEmpty(label))
    {
        series.Points[index].Label = label;
    }
}
else 
{
    /* Otherwise, erase it. */
    series.Points[index].Label = "";
}
© www.soinside.com 2019 - 2024. All rights reserved.