除了清除
labels
的文本之外,一种简单的方法就是使颜色透明。
你可以做整个
Series s1
:
s1.LabelForeColor = checkBox_test.Checked ? Color.Black: Color.Transparent;
..或个人
DataPoints dp
:
dp.LabelForeColor = checkBox_test.Checked ? Color.Blue : Color.Transparent;
另一种解决方案是将标签存储到点的自定义属性中,并在打开标签时将值分配给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 = "";
}