Saturday, May 9, 2009

MS .NET Chart: how to turn point labels on/off

There is no property to turn on or off the visibility of data point labels (i.e. something called enabled or so). The following trick works: make the color transparent if you don’t want to see the labels. Here is some code that works for me:

        private void FlipLabels(Series s)
if (s.LabelForeColor == System.Drawing.Color.Transparent)
s.LabelForeColor = System.Drawing.Color.Black;
s.SmartLabelStyle.CalloutLineColor = System.Drawing.Color.Black;
s.LabelForeColor = System.Drawing.Color.Transparent;
s.SmartLabelStyle.CalloutLineColor = System.Drawing.Color.Transparent;

See also:

Update: too bad I can not change the line style to arrows in a line chart. See:

1 comment:

  1. Thanks alot mate.

    This code is tested and works. Saved me a lot of headache.