17 April 2012

MS Chart Legend Properties and Hide Series Based on Condition

I have a MSChart that displays two series. The data is taken from a database. Sometimes I only want to display one of the series in my chart based on the condition. Follow the bellow steps to hide series.
                 Chart1.Series["Series Name"].Enabled = false; 


We can set Legends properties in code behind as shown bellow steps.
                Chart1.Legends["Default"].Title = "Chart";
                Chart1.Legends["Default"].LegendStyle = LegendStyle.Column;
                Chart1.Legends["Default"].Docking = LegendDocking.Right;
                Chart1.Legends["Default"].Alignment = StringAlignment.Center;
                Chart1.Legends["Default"].BackColor = System.Drawing.Color.Transparent;
                Chart1.Legends["Default"].IsTextAutoFit = false;
                Chart1.Legends["Default"].BorderColor = Color.Black;
                Chart1.Legends["Default"].BorderWidth = 2;
                Chart1.Legends["Default"].BorderDashStyle = ChartDashStyle.Solid;
                Chart1.Legends["Default"].Font = new Font("Arial", 10, FontStyle.Bold);
                Chart1.Legends["Default"].ForeColor = Color.Black;
                Chart1.Legends["Default"].IsEquallySpacedItems = true;


We can set Legends properties in Design 

<Legends>
     <asp:Legend Name="Legend1" Docking="Right" Title="Chart" ForeColor="Black" BorderColor="Black" BorderWidth="2"  BorderDashStyle="Solid" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold"  IsTextAutoFit="False">
     </asp:Legend>
</Legends>

No comments:

Post a Comment