asp.net - How to set a background image for a Chart

Chart background image
The following asp.net c# example code demonstrate us how can we use chart background image in an asp.net application. This tutorial code also explain how can we set or change Chart control's background image programmatically at run time. Chart is an asp.net web server control which allow us to generate chart image for complex financial analysis.

Chart control render in web page as an image. Chart control display visual representation of complex financial statistics. .Net framework's Chart Class allow us to display a background image in Chart control (chart output image). This facility make the chart more attractive and nice looking for visitors.

Chart control BackImage property get or set the background image of the chart control. Chart BackImage property value data type is System.String. This String represent the URL of an image file. This property default value is an empty string. So no background image is set by default.

BackImage property's Image path can be an absolute or a relative URL. We can adjust/position the background image by Chart control's BackImageAlignment and backImageWrapMode properties. Chart BackImageTransparentColor property also helpful to apply transparency on background image.
HowToUseChartBackImage.aspx

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

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Chart1.BackImage = "~/Image/RedForest.gif";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to use Chart BackImage (background image) in asp.net</title>
    <style type="text/css">
        h2
        {
            color:DarkBlue;
            font-style:italic;
            }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2>How to use Chart BackImage in asp.net</h2>
        <hr width="400" align="left" color="DimGray" />
        <br />
        <asp:Chart ID="Chart1" runat="server" BackImage="~/Image/forest.jpg">
            <Titles>
                <asp:Title 
                    Text="Sample chart of salary" 
                    BackColor="IndianRed" 
                    ForeColor="Snow"
                    BorderColor="DarkRed"
                    Font="Comic Sans MS"
                    BorderDashStyle="DashDot"
                    BorderWidth="1" 
                    >
                </asp:Title>
            </Titles>
            <Series>
                <asp:Series 
                    Name="Salary" 
                    YValueType="Int32" 
                    ChartType="Area" 
                    ChartArea="DefaultChartArea"
                    Color="SeaGreen"
                    >
                    <Points>
                        <asp:DataPoint AxisLabel="Maria" YValues="24300" />
                        <asp:DataPoint Color="PaleGoldenrod" AxisLabel="Sakil" YValues="24795" />
                        <asp:DataPoint AxisLabel="KakPakhi" YValues="21250" />
                        <asp:DataPoint Color="Black" AxisLabel="Popy" YValues="32700" />
                        <asp:DataPoint AxisLabel="Noyon" YValues="26500" />
                    </Points>
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="DefaultChartArea" BackColor="PaleGreen" Area3DStyle-Enable3D="true">
                </asp:ChartArea>
            </ChartAreas>
        </asp:Chart>
        <br />
        <asp:Button 
            ID="Button1"
            runat="server"
            Text="Change Chart BackImage"
            Font-Bold="true"
            OnClick="Button1_Click"
            Font-Names="Comic Sans MS"
            ForeColor="DarkBlue"
            Height="45"
            />
    </div>
    </form>
</body>
</html>