Sirawit Lappisatepun
Sirawit Lappisatepun

Reputation: 23

How to hide label of data points in line chart

Please refer to the picture below.

Basically I have a C# chart control with some series on it, I have one series with label (the red line in the picture) but I want to be able to toggle the label on/off. Is that possible? I can't find any properties that can do so.

Thanks a lot.

Chart

Upvotes: 2

Views: 1932

Answers (2)

Sergey
Sergey

Reputation: 640

The alternative solution is to store the labels to the custom properties of the points and assign the values to DataPoint.Label when the labels are toggled on.

/* 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 = "";
}

Upvotes: 0

TaW
TaW

Reputation: 54433

Short of clearing the text of the labels one simple method is to make the color transparent.

You can do it for the whole Series s1:

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

..or for individual DataPoints dp:

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

Upvotes: 2

Related Questions