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;
}
else
{
s.LabelForeColor = System.Drawing.Color.Transparent;
s.SmartLabelStyle.CalloutLineColor = System.Drawing.Color.Transparent;
}
}



See also: http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/threads/



Update: too bad I can not change the line style to arrows in a line chart. See: http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/01b61a40-203d-45dd-8834-7e8f49b974c7/.