asp.net - How to change chart series marker style


Set or change chart series marker style programmatically



The Chart class serves as the root class of the Chart control. The Chart class exposes all of the properties, methods, and events of the Chart Web server control.
The Chart Series collection property stores Series objects which are used to store data that is to be displayed, along with attributes of that data. The Chart ChartAreas collection property stores ChartArea objects, which are primarily used to draw one or more charts using one set of axes.




The following asp.net c# web development tutorial code demonstrates how we can set or change the chart series marker style programmatically. Here we will use the Chart class Series property to get the chart series collection. Then we will get the specified series instance by its name. And then we will set the specified series marker style by setting the Series class MarkerStyle property value.




The Chart Series property gets a SeriesCollection object which contains Series objects. This property value is a SeriesCollection object which contains Series objects.




The SeriesCollection Class represents a collection of Series objects. The SeriesCollection class stores Series objects and also provides methods and properties used to manipulate this collection. Series objects store DataPoint objects, as well as data attributes.




The Series class MarkerStyle property gets or sets the marker style. This property is inherited from DataPointCustomProperties. This property value is a MarkerStyle enumeration value.




The MarkerStyle enumeration represents the style used for a series or data point marker. The MarkerStyle enumeration is used as a value for the MarkerStyle property and the MarkerStyle property.




So finally, the asp.net c# web developers can set or change the Chart series marker style by setting the Series class MarkerStyle property value.






ChartSeriesMarkerStyle.aspx



<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Chart1.Series["NokiaPhone"].MarkerStyle = MarkerStyle.Diamond;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to use Chart Series MarkerStyle in asp.net</title>
<style type="text/css">
h2
{
color:Crimson;
font-style:italic;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Chart example and tutorial: How to use<br /> Chart Series MarkerStyle in asp.net</h2>
<hr width="625" align="left" color="IndianRed" />
<br />
<asp:Chart
ID="Chart1"
runat="server"
Width="625"
BackColor="DarkCyan"
BorderlineColor="AliceBlue"
BorderlineDashStyle="Solid"
BorderlineWidth="2"
>
<Series>
<asp:Series
Name="NokiaPhone"
YValueType="Double"
ChartArea="DefaultChartArea"
ChartType="Bar"
Palette="EarthTones"
>
<Points>
<asp:DataPoint AxisLabel="Nokia N8" YValues="549" />
<asp:DataPoint AxisLabel="Nokia N97 Mini Driver Ed." YValues="399.99" />
<asp:DataPoint AxisLabel="Nokia N97 mini" YValues="379.99" />
<asp:DataPoint AxisLabel="Nokia E72 Driver Edition" YValues="349" />
<asp:DataPoint AxisLabel="Nokia 5800 Driver Edition" YValues="289" />
</Points>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea
Name="DefaultChartArea"
BorderDashStyle="Solid"
BorderWidth="2"
BorderColor="OliveDrab"
BackColor="Olive"
>
<Area3DStyle Enable3D="true" LightStyle="Realistic" />
<AxisX>
<LabelStyle ForeColor="Snow" />
<MajorGrid LineColor="YellowGreen" />
</AxisX>
<AxisY>
<LabelStyle ForeColor="Snow" />
<MajorGrid LineColor="YellowGreen" />
</AxisY>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<br />
<asp:Button
ID="Button1"
runat="server"
Text="Set Chart Series MarkerStyle Diamond"
Font-Bold="true"
OnClick="Button1_Click"
ForeColor="DarkBlue"
Height="45"
/>
</div>
</form>
</body>
</html>








asp.net - How to change chart series marker size


Change chart series marker size programmatically



The Chart class serves as the root class of the Chart control. The Chart class exposes all of the properties, methods, and events of the Chart Web server control.
The Chart Series collection property stores Series objects which are used to store data that is to be displayed, along with attributes of that data. The Chart ChartAreas collection property stores ChartArea objects, which are primarily used to draw one or more charts using one set of axes.




The following asp.net c# web development tutorial code demonstrates how we can change the chart series marker size programmatically. Here we will use the Chart class Series property to get the chart series collection. Then we will get the specified series instance by its name. And then we will set the specified series marker size by setting the Series class MarkerSize property value.




The Chart Series property gets a SeriesCollection object which contains Series objects. This property value is a SeriesCollection object which contains Series objects.




The SeriesCollection Class represents a collection of Series objects. The SeriesCollection class stores Series objects and also provides methods and properties used to manipulate this collection. Series objects store DataPoint objects, as well as data attributes.




The Series class MarkerSize property gets or sets the size of the marker. This property is inherited from DataPointCustomProperties. This property value is an Int32 which is the size of the marker. So finally, the asp.net c# web developers can change the Chart series marker size by setting the Series class MarkerSize property value.






ChartSeriesMarkerSize.aspx



<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Chart1.Series["NokiaPhone"].MarkerSize = 10;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to set change Chart Series MarkerSize programmatically in asp.net</title>
<style type="text/css">
h2
{
color:DarkBlue;
font-style:italic;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Chart example and tutorial: How to set change<br /> Chart Series MarkerSize programmatically in asp.net</h2>
<hr width="625" align="left" color="CornFlowerBlue" />
<br />
<asp:Chart
ID="Chart1"
runat="server"
Width="625"
BackColor="MediumPurple"
BorderlineColor="Orchid"
BorderlineDashStyle="Solid"
BorderlineWidth="2"
>
<Series>
<asp:Series
Name="NokiaPhone"
YValueType="Double"
ChartArea="DefaultChartArea"
ChartType="Bar"
MarkerStyle="Circle"
Color="SeaGreen"
MarkerColor="Green"
>
<Points>
<asp:DataPoint AxisLabel="Nokia N8" YValues="549" />
<asp:DataPoint AxisLabel="Nokia N97 Mini Driver Ed." YValues="399.99" />
<asp:DataPoint AxisLabel="Nokia N97 mini" YValues="379.99" />
<asp:DataPoint AxisLabel="Nokia E72 Driver Edition" YValues="349" />
<asp:DataPoint AxisLabel="Nokia 5800 Driver Edition" YValues="289" />
</Points>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea
Name="DefaultChartArea"
BorderDashStyle="Solid"
BorderWidth="2"
BorderColor="OrangeRed"
BackColor="Orange"
>
<Area3DStyle Enable3D="true" LightStyle="Realistic" />
<AxisX>
<LabelStyle ForeColor="Snow" />
<MajorGrid LineColor="DarkOrange" />
</AxisX>
<AxisY>
<LabelStyle ForeColor="Snow" />
<MajorGrid LineColor="DarkOrange" />
</AxisY>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<br />
<asp:Button
ID="Button1"
runat="server"
Text="Set Chart Series MarkerSize 10"
Font-Bold="true"
OnClick="Button1_Click"
ForeColor="DarkBlue"
Height="45"
/>
</div>
</form>
</body>
</html>








asp.net - How to change chart legend title separator color


Change the Chart legend title separator color



The Chart class serves as the root class of the Chart control. The Chart class exposes all of the properties, methods, and events of the Chart Web server control.
The Chart Series collection property stores Series objects which are used to store data that is to be displayed, along with attributes of that data. The Chart ChartAreas collection property stores ChartArea objects, which are primarily used to draw one or more charts using one set of axes.




The following asp.net c# web development tutorial code demonstrates how we can change the Chart legend title default separator color programmatically. Here we will use the Chart class Legends property to get the legend collection. Then we will get the specified legend instance by its id. And then we will set or change the Chart legend’s title separator color by setting the Legend class TitleSeparatorColor property value.




The Chart Legends property gets or sets a LegendCollection object that is used to store all Legend objects used by the Chart control. This property value is a LegendCollection that is used to store all Legend objects. This Chart collection property stores all Legend objects used by the Chart control.




The Legend class represents the legend for the chart image. The Legend class encapsulates all the functionality of the Chart control's legend and is exposed using the Legends collection property of the root Chart object. In a Chart object can be any number of legends for a chart image.




The Legend class TitleSeparatorColor property gets or sets the color of the legend title separator. This property value is a Color that is used to draw the color of the legend title separator. The default value of this property is Black.




ChartLegendTitleSeparatorColor.aspx



<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Chart1.Legends["Legend1"].TitleSeparatorColor = System.Drawing.Color.BlanchedAlmond;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to set change Chart Legend TitleSeparatorColor programmatically in asp.net</title>
<style type="text/css">
h2
{
color:Crimson;
font-style:italic;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Chart example and tutorial: How to set change Chart Legend<br /> TitleSeparatorColor programmatically in asp.net</h2>
<hr width="625" align="left" color="IndianRed" />
<br />
<asp:Chart
ID="Chart1"
runat="server"
Width="625"
BackColor="DarkCyan"
BorderlineColor="AliceBlue"
BorderlineDashStyle="Solid"
BorderlineWidth="2"
>
<Legends>
<asp:Legend
Name="Legend1"
BackColor="DodgerBlue"
ForeColor="Snow"
BorderColor="MidnightBlue"
Docking="Right"
TableStyle="Wide"
Title="Nokia Phone Legend"
TitleForeColor="Snow"
TitleSeparator="DoubleLine"
>
</asp:Legend>
</Legends>
<Series>
<asp:Series
Name="NokiaPhone"
YValueType="Double"
ChartArea="DefaultChartArea"
ChartType="Pyramid"
Palette="Excel"
>
<Points>
<asp:DataPoint AxisLabel="Nokia N8" YValues="549" />
<asp:DataPoint AxisLabel="Nokia N97 Mini Driver Ed." YValues="399.99" />
<asp:DataPoint AxisLabel="Nokia E72 Driver Edition" YValues="349" />
<asp:DataPoint AxisLabel="X6 16GB Driver Edition" YValues="329" />
<asp:DataPoint AxisLabel="Nokia C6" YValues="309" />
<asp:DataPoint AxisLabel="Nokia 5800 Driver Edition" YValues="289" />
</Points>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea
Name="DefaultChartArea"
BorderDashStyle="Solid"
BorderWidth="2"
BorderColor="OliveDrab"
BackColor="DarkOliveGreen"
>
<Area3DStyle Enable3D="true" LightStyle="Realistic" />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<br />
<asp:Button
ID="Button1"
runat="server"
Text="Set Chart Legend TitleSeparatorColor BlanchedAlmond"
Font-Bold="true"
OnClick="Button1_Click"
ForeColor="DarkBlue"
Height="45"
/>
</div>
</form>
</body>
</html>








asp.net - How to create a chart legend title


Create the Chart legend title programmatically



The Chart class serves as the root class of the Chart control. The Chart class exposes all of the properties, methods, and events of the Chart Web server control.
The Chart Series collection property stores Series objects which are used to store data that is to be displayed, along with attributes of that data. The Chart ChartAreas collection property stores ChartArea objects, which are primarily used to draw one or more charts using one set of axes.




The following asp.net c# web development tutorial code demonstrates how we can create the Chart legend title programmatically. Here we will use the Chart class Legends property to get the legend collection. Then we will get the specified legend instance by its id. And then we will create or change the Chart legend’s title by setting the Legend class Title property value.




The Chart Legends property gets or sets a LegendCollection object that is used to store all Legend objects used by the Chart control. This property value is a LegendCollection that is used to store all Legend objects. This Chart collection property stores all Legend objects used by the Chart control.




The Legend class represents the legend for the chart image. The Legend class encapsulates all the functionality of the Chart control's legend and is exposed using the Legends collection property of the root Chart object. In a Chart object can be any number of legends for a chart image.




The Legend class Title property gets or sets the text of the legend title. The Legend Title property value is a String that represents the legend title text. The default value of this property is a zero-length string.




So finally, the asp.net web developers can create a title for a Chart legend programmatically by setting the Legend class Title property value. They also can change a specified legend’s title text by changing its Title property value.





ChartLegendTitle.aspx



<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Chart1.Legends["Legend1"].Title = "Nokia Phone Legend";
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to create Chart Legend Title programmatically in asp.net</title>
<style type="text/css">
h2
{
color:Crimson;
font-style:italic;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Chart example and tutorial: How to create Chart Legend<br /> Title programmatically in asp.net</h2>
<hr width="625" align="left" color="IndianRed" />
<br />
<asp:Chart
ID="Chart1"
runat="server"
Width="625"
BackColor="Navy"
BorderlineColor="SlateBlue"
BorderlineDashStyle="Solid"
BorderlineWidth="2"
>
<Legends>
<asp:Legend
Name="Legend1"
BackColor="AliceBlue"
ForeColor="CadetBlue"
BorderColor="LightBlue"
Docking="Right"
>
</asp:Legend>
</Legends>
<Series>
<asp:Series
Name="NokiaPhone"
YValueType="Double"
ChartArea="DefaultChartArea"
ChartType="Pyramid"
Palette="Fire"
>
<Points>
<asp:DataPoint AxisLabel="Nokia N8" YValues="549" />
<asp:DataPoint AxisLabel="Nokia N97 mini" YValues="379.99" />
<asp:DataPoint AxisLabel="X6 16GB Driver Edition" YValues="329" />
<asp:DataPoint AxisLabel="Nokia C6" YValues="309" />
</Points>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea
Name="DefaultChartArea"
BorderDashStyle="DashDotDot"
BorderWidth="2"
BorderColor="DodgerBlue"
BackColor="MidnightBlue"
>
<Area3DStyle Enable3D="true" LightStyle="Realistic" />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<br />
<asp:Button
ID="Button1"
runat="server"
Text="Add Chart Legend Title"
Font-Bold="true"
OnClick="Button1_Click"
ForeColor="DarkBlue"
Height="45"
/>
</div>
</form>
</body>
</html>








How to show or hide chart legend in asp.net


Show or hide the Chart legend programmatically



The Chart class serves as the root class of the Chart control. The Chart class exposes all of the properties, methods, and events of the Chart Web server control.
The Chart Series collection property stores Series objects which are used to store data that is to be displayed, along with attributes of that data. The Chart ChartAreas collection property stores ChartArea objects, which are primarily used to draw one or more charts using one set of axes.




The following asp.net c# web development tutorial code demonstrates how we can show or hide (enable or disable) the Chart legend programmatically. Here we will use the Chart class Legends property to get the legend collection. Then we will get the specified legend instance by its id. And then we will change the Chart legend’s visibility by setting the Legend class Enabled property value.




The Chart Legends property gets or sets a LegendCollection object that is used to store all Legend objects used by the Chart control. This property value is a LegendCollection that is used to store all Legend objects. This Chart collection property stores all Legend objects used by the Chart control.




The Legend class represents the legend for the chart image. The Legend class encapsulates all the functionality of the Chart control's legend and is exposed using the Legends collection property of the root Chart object. In a Chart object can be any number of legends for a chart image.




The Legend class Enabled property gets or sets a value that determines if the legend is enabled. The Enabled property value is a Boolean. The value is true if the legend is enabled otherwise the value is false. The default value of this property is true.




So finally, the asp.net c# developers can hide a Chart legend by settings the Legend class Enabled property value to false. They also can visible the Chart legend by setting this Enabled property value to true.





EnableDisableChartLegend.aspx



<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Chart1.Legends["Legend1"].Enabled = false;
}
protected void Button2_Click(object sender, System.EventArgs e)
{
Chart1.Legends["Legend1"].Enabled = true;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to enable disable(show hide) Chart Legend programmatically in asp.net</title>
<style type="text/css">
h2
{
color:DarkBlue;
font-style:italic;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Chart example and tutorial: How to enable disable(show hide)<br /> Chart Legend programmatically in asp.net</h2>
<hr width="625" align="left" color="LightBlue" />
<br />
<asp:Chart
ID="Chart1"
runat="server"
Width="625"
BackColor="Purple"
BorderlineColor="Orchid"
BorderlineDashStyle="Dash"
BorderlineWidth="2"
>
<Legends>
<asp:Legend
Name="Legend1"
BackColor="Crimson"
BackGradientStyle="DiagonalRight"
ForeColor="Snow"
BackSecondaryColor="Pink"
BorderColor="IndianRed"
>
</asp:Legend>
</Legends>
<Series>
<asp:Series
Name="NokiaPhone"
YValueType="Double"
ChartArea="DefaultChartArea"
ChartType="Pie"
Palette="SemiTransparent"
>
<Points>
<asp:DataPoint AxisLabel="Nokia N8" YValues="549" />
<asp:DataPoint AxisLabel="Nokia N97 mini" YValues="379.99" />
<asp:DataPoint AxisLabel="X6 16GB Driver Edition" YValues="329" />
<asp:DataPoint AxisLabel="Nokia C6" YValues="309" />
</Points>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea
Name="DefaultChartArea"
BorderDashStyle="Dot"
BorderWidth="2"
BorderColor="DarkOrchid"
BackColor="Orchid"
>
<Area3DStyle Enable3D="true" LightStyle="Realistic" />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<br />
<asp:Button
ID="Button1"
runat="server"
Text="Hide Chart Legend"
Font-Bold="true"
OnClick="Button1_Click"
ForeColor="DarkBlue"
Height="45"
/>
<asp:Button
ID="Button2"
runat="server"
Text="Show Chart Legend"
Font-Bold="true"
OnClick="Button2_Click"
ForeColor="DarkBlue"
Height="45"
/>
</div>
</form>
</body>
</html>








asp.net - How to change chart legend maximum auto size


Change the Chart legend maximum auto size



The Chart class serves as the root class of the Chart control. The Chart class exposes all of the properties, methods, and events of the Chart Web server control.
The Chart Series collection property stores Series objects which are used to store data that is to be displayed, along with attributes of that data. The Chart ChartAreas collection property stores ChartArea objects, which are primarily used to draw one or more charts using one set of axes.




The following asp.net c# web development tutorial code demonstrates how we can change the Chart legend maximum auto size programmatically. Here we will use the Chart class Legends property to get the legend collection. Then we will get the specified legend instance by its id. And then we will set or change the Chart legend’s maximum auto-size by setting the Legend class MaximumAutoSize property value.




The Chart Legends property gets or sets a LegendCollection object that is used to store all Legend objects used by the Chart control. This property value is a LegendCollection that is used to store all Legend objects. This Chart collection property stores all Legend objects used by the Chart control.




The Legend class represents the legend for the chart image. The Legend class encapsulates all the functionality of the Chart control's legend and is exposed using the Legends collection property of the root Chart object. In a Chart object can be any number of legends for a chart image.




The Legend class MaximumAutoSize property gets or sets the maximum size of the legend, measured as a percentage of the chart area. This MaximumAutoSize property value is used by the automatic layout algorithm. This property value is a Single which is a float value that represents the maximum size of the legend. The Single value type represents a single-precision floating-point number.





ChartLegendMaximumAutoSize.aspx



<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Chart1.Legends["Legend1"].MaximumAutoSize = 20;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to set change Chart Legend MaximumAutoSize programmatically in asp.net</title>
<style type="text/css">
h2
{
color:DarkBlue;
font-style:italic;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Chart example and tutorial: How to set change Chart Legend<br /> MaximumAutoSize programmatically in asp.net</h2>
<hr width="625" align="left" color="LightBlue" />
<br />
<asp:Chart
ID="Chart1"
runat="server"
Width="625"
BackColor="Maroon"
BorderlineColor="Magenta"
BorderlineDashStyle="Solid"
BorderlineWidth="2"
>
<Legends>
<asp:Legend
Name="Legend1"
BackColor="Snow"
ForeColor="SaddleBrown"
BorderColor="IndianRed"
Docking="Right"
>
</asp:Legend>
</Legends>
<Series>
<asp:Series
Name="NokiaPhone"
YValueType="Double"
ChartArea="DefaultChartArea"
ChartType="Pie"
Palette="Berry"
>
<Points>
<asp:DataPoint AxisLabel="Nokia N8" YValues="549" />
<asp:DataPoint AxisLabel="Nokia N97 mini" YValues="379.99" />
<asp:DataPoint AxisLabel="X6 16GB Driver Edition" YValues="329" />
<asp:DataPoint AxisLabel="Nokia C6" YValues="309" />
</Points>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea
Name="DefaultChartArea"
BorderDashStyle="Dot"
BorderWidth="2"
BorderColor="DarkOrchid"
BackColor="DarkSalmon"
>
<Area3DStyle Enable3D="true" LightStyle="Realistic" />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<br />
<asp:Button
ID="Button1"
runat="server"
Text="Set Chart Legend MaximumAutoSize 20"
Font-Bold="true"
OnClick="Button1_Click"
ForeColor="DarkBlue"
Height="45"
/>
</div>
</form>
</body>
</html>








asp.net - How to change chart legend style programmatically


Change the Chart legend style programmatically



The Chart class serves as the root class of the Chart control. The Chart class exposes all of the properties, methods, and events of the Chart Web server control.
The Chart Series collection property stores Series objects which are used to store data that is to be displayed, along with attributes of that data. The Chart ChartAreas collection property stores ChartArea objects, which are primarily used to draw one or more charts using one set of axes.




The following asp.net c# web development tutorial code demonstrates how we can change the Chart legend style programmatically. Here we will use the Chart class Legends property to get the legend collection. Then we will get the specified legend instance by its id. And then we will set or change the Chart legend’s default style by setting the Legend class LegendStyle property value.




The Chart Legends property gets or sets a LegendCollection object that is used to store all Legend objects used by the Chart control. This property value is a LegendCollection that is used to store all Legend objects. This Chart collection property stores all Legend objects used by the Chart control.




The Legend class represents the legend for the chart image. The Legend class encapsulates all the functionality of the Chart control's legend and is exposed using the Legends collection property of the root Chart object. In a Chart object can be any number of legends for a chart image.




The Legend class LegendStyle property gets or sets the style of the legend. This property value is a LegendStyle enumeration value that determines the legend style. The default value of this property is Table.




The Chart legend is displayed as a series of items in a table by default. The asp.net web developers can specify whether to expand items in the table width-wise or height-wise by setting the TableStyle property.




The asp.net web developers can select a style from the three possible styles for a legend. Those legend styles are Column, Row, and Table.




In a Column style, legend items are displayed in one column, with multiple rows. Most commonly the asp.net developers used it when the legend is docked to the left or right of the chart.




In a Row style, legend items are displayed in one row, with multiple columns. Most commonly the asp.net developers used it when the legend is docked to the top or bottom of the chart.




In a Table style, legend items are displayed using multiple columns and rows.





ChartLegendLegendStyle.aspx



<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html">

<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Chart1.Legends["Legend1"].LegendStyle = LegendStyle.Column;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to set change Chart Legend LegendStyle programmatically in asp.net</title>
<style type="text/css">
h2
{
color:DarkBlue;
font-style:italic;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Chart example and tutorial: How to set change Chart Legend<br /> LegendStyle programmatically in asp.net</h2>
<hr width="625" align="left" color="LightBlue" />
<br />
<asp:Chart
ID="Chart1"
runat="server"
Width="625"
BackColor="Violet"
BorderlineColor="DarkViolet"
BorderlineDashStyle="Dash"
BorderlineWidth="2"
>
<Legends>
<asp:Legend
Name="Legend1"
BackColor="Snow"
ForeColor="Green"
BorderColor="SeaGreen"
Docking="Top"
>
</asp:Legend>
</Legends>
<Series>
<asp:Series
Name="NokiaPhone"
YValueType="Double"
ChartArea="DefaultChartArea"
ChartType="Pyramid"
Palette="SeaGreen"
>
<Points>
<asp:DataPoint AxisLabel="Nokia N8" YValues="549" />
<asp:DataPoint AxisLabel="Nokia N97 mini" YValues="379.99" />
<asp:DataPoint AxisLabel="X6 16GB Driver Edition" YValues="329" />
<asp:DataPoint AxisLabel="Nokia C6" YValues="309" />
</Points>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea
Name="DefaultChartArea"
BorderDashStyle="Dot"
BorderWidth="2"
BorderColor="MediumOrchid"
BackColor="MediumPurple"
>
<Area3DStyle Enable3D="true" LightStyle="Realistic" />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<br />
<asp:Button
ID="Button1"
runat="server"
Text="Set Chart Legend LegendStyle Column"
Font-Bold="true"
OnClick="Button1_Click"
ForeColor="DarkBlue"
Height="45"
/>
</div>
</form>
</body>
</html>








asp.net - How to change a chart legend text color


Change a Chart legend’s text color



The Chart class serves as the root class of the Chart control. The Chart class exposes all of the properties, methods, and events of the Chart Web server control.
The Chart Series collection property stores Series objects which are used to store data that is to be displayed, along with attributes of that data. The Chart ChartAreas collection property stores ChartArea objects, which are primarily used to draw one or more charts using one set of axes.




The following asp.net c# web development tutorial code demonstrates how we can change a Chart legend’s text color. Here we will use the Chart class Legends property to get the legend collection. Then we will get the specified legend instance by its id. And then we will change the legend text color by changing its ForeColor property value.




The Chart Legends property gets or sets a LegendCollection object that is used to store all Legend objects used by the Chart control. This property value is a LegendCollection that is used to store all Legend objects. This Chart collection property stores all Legend objects used by the Chart control.




The Legend class represents the legend for the chart image. The Legend class encapsulates all the functionality of the Chart control's legend and is exposed using the Legends collection property of the root Chart object. In a Chart object can be any number of legends for a chart image.




The Legend class ForeColor property gets or sets the color of the legend text. This property value is a Color value that represents the color of the legend text. The ForeColor property is used to set the Chart legend text color.






ChartLegendForeColor.aspx



<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Chart1.Legends["Legend1"].ForeColor = System.Drawing.Color.Crimson;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to set change Chart Legend ForeColor(font text color) programmatically in asp.net</title>
<style type="text/css">
h2
{
color:DarkBlue;
font-style:italic;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Chart example and tutorial: How to set change Chart Legend<br /> ForeColor (font text color) programmatically in asp.net</h2>
<hr width="625" align="left" color="LightBlue" />
<br />
<asp:Chart
ID="Chart1"
runat="server"
Width="625"
BackColor="Tomato"
BorderlineColor="Thistle"
BorderlineDashStyle="Dash"
BorderlineWidth="2"
>
<Legends>
<asp:Legend
Name="Legend1"
BackColor="Snow"
ForeColor="Green"
BorderColor="HotPink"
DockedToChartArea="DefaultChartArea"
>
</asp:Legend>
</Legends>
<Series>
<asp:Series
Name="NokiaPhone"
YValueType="Double"
ChartArea="DefaultChartArea"
ChartType="Pie"
Palette="SemiTransparent"
>
<Points>
<asp:DataPoint AxisLabel="Nokia N8" YValues="549" />
<asp:DataPoint AxisLabel="Nokia N97 mini" YValues="379.99" />
<asp:DataPoint AxisLabel="X6 16GB Driver Edition" YValues="329" />
<asp:DataPoint AxisLabel="Nokia C6" YValues="309" />
</Points>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea
Name="DefaultChartArea"
BorderDashStyle="Dot"
BorderWidth="2"
BorderColor="Pink"
BackColor="OrangeRed"
>
<Area3DStyle Enable3D="true" LightStyle="Realistic" />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<br />
<asp:Button
ID="Button1"
runat="server"
Text="Set Chart Legend ForeColor Crimson"
Font-Bold="true"
OnClick="Button1_Click"
ForeColor="DarkBlue"
Height="45"
/>
</div>
</form>
</body>
</html>








How to change chart legend docking in asp.net


Change a Chart legend’s docking



The Chart class serves as the root class of the Chart control. The Chart class exposes all of the properties, methods, and events of the Chart Web server control.
The Chart Series collection property stores Series objects which are used to store data that is to be displayed, along with attributes of that data. The Chart ChartAreas collection property stores ChartArea objects, which are primarily used to draw one or more charts using one set of axes.




The following asp.net c# web development tutorial code demonstrates how we can change the docking of a Chart legend. Here we will use the Chart class Legends property to get the legend collection. Then we will get the specified legend instance by its id. And then we will change the Chart legend docking by setting the Legend class Docking property value.




The Chart Legends property gets or sets a LegendCollection object that is used to store all Legend objects used by the Chart control. This property value is a LegendCollection that is used to store all Legend objects. This Chart collection property stores all Legend objects used by the Chart control.




The Legend class represents the legend for the chart image. The Legend class encapsulates all the functionality of the Chart control's legend and is exposed using the Legends collection property of the root Chart object. In a Chart object can be any number of legends for a chart image.




The Legend class Docking property gets or sets a value that determines where the legend is docked. This property value is a Docking enumeration value that determines where the legend is docked. The default value is Right.




The Chart Legend can be docked to the top, left, bottom, or right of either the entire chart image or the inside or outside of a chart area. The Docking enumeration specifies where a chart element, such as a legend or title, will be docked on the chart.





ChartLegendDocking.aspx



<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Chart1.Legends["Legend1"].Docking = Docking.Bottom;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to set change Chart Legend Docking programmatically in asp.net</title>
<style type="text/css">
h2
{
color:DarkBlue;
font-style:italic;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Chart example and tutorial: How to set change<br /> Chart Legend Docking programmatically in asp.net</h2>
<hr width="625" align="left" color="LightBlue" />
<br />
<asp:Chart
ID="Chart1"
runat="server"
Width="625"
BackColor="DarkSalmon"
BorderlineColor="Salmon"
BorderlineDashStyle="Dash"
BorderlineWidth="2"
>
<Legends>
<asp:Legend
Name="Legend1"
BackColor="Crimson"
BackGradientStyle="DiagonalLeft"
ForeColor="Snow"
BackSecondaryColor="Pink"
BorderColor="IndianRed"
>
</asp:Legend>
</Legends>
<Series>
<asp:Series
Name="NokiaPhone"
YValueType="Double"
ChartArea="DefaultChartArea"
ChartType="Pie"
Palette="Excel"
>
<Points>
<asp:DataPoint AxisLabel="Nokia N8" YValues="549" />
<asp:DataPoint AxisLabel="Nokia N97 mini" YValues="379.99" />
<asp:DataPoint AxisLabel="X6 16GB Driver Edition" YValues="329" />
<asp:DataPoint AxisLabel="Nokia C6" YValues="309" />
</Points>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea
Name="DefaultChartArea"
BorderDashStyle="Dot"
BorderWidth="2"
BorderColor="SandyBrown"
BackColor="IndianRed"
>
<Area3DStyle Enable3D="true" LightStyle="Realistic" />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<br />
<asp:Button
ID="Button1"
runat="server"
Text="Set Chart Legend Docking Bottom"
Font-Bold="true"
OnClick="Button1_Click"
ForeColor="DarkBlue"
Height="45"
/>
</div>
</form>
</body>
</html>








asp.net - How to set the chart area to dock a legend


Set the chart area where a legend will be docked



The Chart class serves as the root class of the Chart control. The Chart class exposes all of the properties, methods, and events of the Chart Web server control.
The Chart Series collection property stores Series objects which are used to store data that is to be displayed, along with attributes of that data. The Chart ChartAreas collection property stores ChartArea objects, which are primarily used to draw one or more charts using one set of axes.




The following asp.net c# web development tutorial code demonstrates how we can set the ChartArea where a specified legend will be docked. Here we will use the Chart class Legends property to get the legend collection. Then we will get the specified legend instance by its id. And then we will set the chart area where the legend will be docked by setting the Legend class DockedToChartArea property value.




The Chart Legends property gets or sets a LegendCollection object that is used to store all Legend objects used by the Chart control. This property value is a LegendCollection that is used to store all Legend objects. This Chart collection property stores all Legend objects used by the Chart control.




The Legend class represents the legend for the chart image. The Legend class encapsulates all the functionality of the Chart control's legend and is exposed using the Legends collection property of the root Chart object. In a Chart object can be any number of legends for a chart image.




The ChartArea class represents a chart area on the chart image. The chart area is the rectangular area that encompasses the plot position, the tick marks, the axis labels, and the axis titles on the chart.




The Legend class DockedToChartArea property gets or sets the name of the ChartArea where the legend will be docked. This property value is a String which represents the name of the ChartArea where this legend will be docked. The default value of this property is the empty string.






ChartLegendDockedToChartArea.aspx



<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Chart1.Legends["Legend1"].DockedToChartArea = "DefaultChartArea";
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to use DockedToChartArea to show Chart Legend in specific ChartArea in asp.net</title>
<style type="text/css">
h2
{
color:DarkBlue;
font-style:italic;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Chart example and tutorial: How to show<br /> Chart Legend in specific ChartArea in asp.net</h2>
<hr width="625" align="left" color="LightBlue" />
<br />
<asp:Chart
ID="Chart1"
runat="server"
Width="625"
BackColor="SkyBlue"
BorderlineColor="SteelBlue"
BorderlineDashStyle="Dash"
BorderlineWidth="2"
>
<Legends>
<asp:Legend
Name="Legend1"
BackColor="OliveDrab"
BackGradientStyle="DiagonalRight"
ForeColor="Snow"
BackSecondaryColor="YellowGreen"
BorderColor="LawnGreen"
>
</asp:Legend>
</Legends>
<Series>
<asp:Series
Name="NokiaPhone"
YValueType="Double"
ChartArea="DefaultChartArea"
ChartType="Pie"
Palette="SemiTransparent"
>
<Points>
<asp:DataPoint AxisLabel="Nokia N8" YValues="549" />
<asp:DataPoint AxisLabel="Nokia N97 mini" YValues="379.99" />
<asp:DataPoint AxisLabel="X6 16GB Driver Edition" YValues="329" />
<asp:DataPoint AxisLabel="Nokia C6" YValues="309" />
</Points>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea
Name="DefaultChartArea"
BorderDashStyle="Dot"
BorderWidth="2"
BorderColor="LightBlue"
BackColor="CornflowerBlue"
>
<Area3DStyle Enable3D="true" LightStyle="Realistic" />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<br />
<asp:Button
ID="Button1"
runat="server"
Text="Show Chart Legend in DefaultChartArea"
Font-Bold="true"
OnClick="Button1_Click"
ForeColor="DarkBlue"
Height="45"
/>
</div>
</form>
</body>
</html>








asp.net - How to create a chart legend programmatically


Add a chart legend programmatically



The Chart class serves as the root class of the Chart control. The Chart class exposes all of the properties, methods, and events of the Chart Web server control.
The Chart Series collection property stores Series objects which are used to store data that is to be displayed, along with attributes of that data. The Chart ChartAreas collection property stores ChartArea objects, which are primarily used to draw one or more charts using one set of axes.




The following asp.net c# web development tutorial code demonstrates how we can create a Chart legend programmatically. Here we will use the Chart class Legends property to get the legend collection. Then we will call the LegendCollection class Add() method to create and add a new legend to the legend collection.




The Chart Legends property gets or sets a LegendCollection object that is used to store all Legend objects used by the Chart control. This property value is a LegendCollection that is used to store all Legend objects. This Chart collection property stores all Legend objects used by the Chart control.




The LegendCollection class represents a collection of Legend objects. The LegendCollection class is implemented as the Legends collection property of the root Chart object. The asp.net web developers can append, insert or remove Legend objects from the collection at either design time or run time.




The LegendCollection class Add(String) method adds the specified Legend object to the end of the collection.
The Add(string name) method has a parameter named name. The name parameter is a String which is the name of the legend to be added. The LegendCollection class Add() method returns a Legend.






CreateChartLegend.aspx



<%@ Page Language="C#" AutoEventWireup="true" %>
<%@Import Namespace="System.Web.UI.DataVisualization.Charting" %>

<!DOCTYPE html>

<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Chart1.Legends.Add("ChartLegend");
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to create Chart Legend programmatically in asp.net</title>
<style type="text/css">
h2
{
color:DarkBlue;
font-style:italic;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Chart example and tutorial: How to create<br /> Chart Legend programmatically in asp.net</h2>
<hr width="625" align="left" color="LightBlue" />
<br />
<asp:Chart
ID="Chart1"
runat="server"
Width="625"
BackColor="BurlyWood"
BorderlineColor="SandyBrown"
BorderlineDashStyle="Solid"
BorderlineWidth="2"
>
<Series>
<asp:Series
Name="NokiaPhone"
YValueType="Double"
ChartArea="DefaultChartArea"
ChartType="Pie"
Palette="Chocolate"
>
<Points>
<asp:DataPoint AxisLabel="Nokia N8" YValues="549" />
<asp:DataPoint AxisLabel="Nokia N97 mini" YValues="379.99" />
<asp:DataPoint AxisLabel="X6 16GB Driver Edition" YValues="329" />
<asp:DataPoint AxisLabel="Nokia C6" YValues="309" />
</Points>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea
Name="DefaultChartArea"
BorderDashStyle="Dot"
BorderWidth="2"
BorderColor="Green"
BackColor="DarkGreen"
>
<Area3DStyle Enable3D="true" LightStyle="Realistic" />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<br />
<asp:Button
ID="Button1"
runat="server"
Text="Create Chart Legend"
Font-Bold="true"
OnClick="Button1_Click"
ForeColor="DarkBlue"
Height="45"
/>
</div>
</form>
</body>
</html>








asp.net - How to change chart legend alignment


Change a Chart legend’s alignment



The Chart class serves as the root class of the Chart control. The Chart class exposes all of the properties, methods, and events of the Chart Web server control.
The Chart Series collection property stores Series objects which are used to store data that is to be displayed, along with attributes of that data. The Chart ChartAreas collection property stores ChartArea objects, which are primarily used to draw one or more charts using one set of axes.




The following asp.net c# web development tutorial code demonstrates how we can change a Chart legend’s alignment. Here we will use the Chart class Legends property to get the legend collection. Then we will get the specified legend instance by its id. And then we will change the Chart legend’s alignment by setting the Legend class Alignment property value.




The Chart Legends property gets or sets a LegendCollection object that is used to store all Legend objects used by the Chart control. This property value is a LegendCollection that is used to store all Legend objects. This Chart collection property stores all Legend objects used by the Chart control.




The Legend class represents the legend for the chart image. The Legend class encapsulates all the functionality of the Chart control's legend and is exposed using the Legends collection property of the root Chart object. In a Chart object can be any number of legends for a chart image.




The Legend class Alignment property gets or sets the alignment of the legend. This property value is a StringAlignment which is a .NET Framework StringAlignment enumeration value that represents the alignment of the legend. The default value is Near.




The Chart legend can be aligned so that it is Near, Center, or Far. Its alignment is also affected by the Docking property setting. But setting the Legend Alignment property will have no effect if the Position property is not set to Auto.




The StringAlignment enumeration specifies the alignment of a text string relative to its layout rectangle.






ChartLegendAlignment.aspx



<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Chart1.Legends["Legend1"].Alignment = System.Drawing.StringAlignment.Center;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to set change Chart Legend Alignment programmatically in asp.net</title>
<style type="text/css">
h2
{
color:DarkBlue;
font-style:italic;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Chart example and tutorial: How to set change<br /> Chart Legend Alignment programmatically in asp.net</h2>
<hr width="625" align="left" color="LightBlue" />
<br />
<asp:Chart
ID="Chart1"
runat="server"
Width="625"
BackColor="DarkRed"
BorderlineColor="SandyBrown"
BorderlineDashStyle="Solid"
BorderlineWidth="2"
>
<Legends>
<asp:Legend
Name="Legend1"
>
</asp:Legend>
</Legends>
<Series>
<asp:Series
Name="NokiaPhone"
YValueType="Double"
ChartArea="DefaultChartArea"
ChartType="Pie"
Palette="Chocolate"
>
<Points>
<asp:DataPoint AxisLabel="Nokia N8" YValues="549" />
<asp:DataPoint AxisLabel="Nokia N97 mini" YValues="379.99" />
<asp:DataPoint AxisLabel="X6 16GB Driver Edition" YValues="329" />
<asp:DataPoint AxisLabel="Nokia C6" YValues="309" />
</Points>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea
Name="DefaultChartArea"
BorderDashStyle="Dot"
BorderWidth="2"
BorderColor="Crimson"
BackColor="SaddleBrown"
>
<Area3DStyle Enable3D="true" LightStyle="Realistic" />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<br />
<asp:Button
ID="Button1"
runat="server"
Text="Set Chart Legend Alignment Center"
Font-Bold="true"
OnClick="Button1_Click"
ForeColor="DarkBlue"
Height="45"
/>
</div>
</form>
</body>
</html>