Enable and disable (show and hide) Chart Axis (AxisX AxisY) programmatically
EnableDisableChartAxis.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.ChartAreas[0].AxisX.Enabled = AxisEnabled.False;
Chart1.ChartAreas[0].AxisY.Enabled = AxisEnabled.False;
}
protected void Button2_Click(object sender, System.EventArgs e)
{
Chart1.ChartAreas[0].AxisX.Enabled = AxisEnabled.True;
Chart1.ChartAreas[0].AxisY.Enabled = AxisEnabled.True;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to enable disable (show hide) Chart Axis (AxisX AxisY) 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 Axis (AxisX AxisY) programmatically in asp.net</h2>
<hr width="525" align="left" color="LightBlue" />
<br />
<asp:Chart
ID="Chart1"
runat="server"
Width="525"
BackColor="DarkSeaGreen"
BorderlineColor="DarkGreen"
BorderlineDashStyle="Solid"
>
<Series>
<asp:Series
Name="AnnualSalary"
YValueType="Int32"
ChartArea="DefaultChartArea"
ChartType="Bar"
Palette="Fire"
>
<Points>
<asp:DataPoint AxisLabel="Ashis" YValues="39150" />
<asp:DataPoint AxisLabel="Asha" YValues="26495" />
<asp:DataPoint AxisLabel="Hamira" YValues="9750" />
<asp:DataPoint AxisLabel="Rebeka" YValues="9450" />
<asp:DataPoint AxisLabel="Anika" YValues="16450" />
</Points>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea
Name="DefaultChartArea"
BorderDashStyle="Solid"
BorderWidth="2"
BorderColor="DarkGreen"
BackColor="Green"
>
<Area3DStyle Enable3D="true" LightStyle="Realistic" />
<AxisX>
<MajorGrid
LineDashStyle="DashDotDot"
LineColor="DarkSeaGreen"
LineWidth="2"
/>
</AxisX>
<AxisY>
<MajorGrid
LineDashStyle="DashDotDot"
LineColor="DarkSeaGreen"
LineWidth="2"
/>
</AxisY>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<br />
<asp:Button
ID="Button1"
runat="server"
Text="Hide Chart Axis"
Font-Bold="true"
OnClick="Button1_Click"
ForeColor="DarkBlue"
Height="45"
/>
<asp:Button
ID="Button2"
runat="server"
Text="Show Chart Axis"
Font-Bold="true"
OnClick="Button2_Click"
ForeColor="DarkBlue"
Height="45"
/>
</div>
</form>
</body>
</html>

