Tuesday, September 7, 2010

stack bar chart in asp.net 3.4

-- html code


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.DataVisualization.Charting" tagprefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
  
        <asp:CHART id="Chart1" runat="server" Palette="BrightPastel"
            BackColor="#EFE6F7" Width="688px" Height="440px" BorderDashStyle="Solid"
            BackGradientStyle="TopBottom" BorderWidth="2" BorderColor="181, 64, 1"
            onclick="Chart1_Click">
                            <titles>
                                <asp:Title ShadowColor="32, 0, 0, 0" Font="Trebuchet MS, 14.25pt, style=Bold" ShadowOffset="3" Text="Graycell Demo" Name="Title1" ForeColor="26, 59, 105"></asp:Title>
                            </titles>
                            <legends>
                                <asp:Legend TitleFont="Microsoft Sans Serif, 8pt, style=Bold" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold" IsTextAutoFit="False" Enabled="false" Name="Default"></asp:Legend>
                            </legends>
                            <borderskin SkinStyle="Emboss"></borderskin>
                            <series>
                              <asp:Series YValueType="String" XValueType="String" Name="FullName" IsValueShownAsLabel="true" IsVisibleInLegend="false" />                         
                            
                            
                              <%-- <asp:Series XValueType="Double" IsValueShownAsLabel="true" LegendText="Billable hours"  ChartType="StackedColumn" Color="LightGreen"
                                    Name="Billable" BorderColor="180, 26, 59, 105" CustomProperties="DrawingStyle=Cylinder" ShadowColor="DarkGreen">
                                </asp:Series>
                                <asp:Series XValueType="Double" IsValueShownAsLabel="true" Legend="non Billable hours" ChartType="StackedColumn" Color="LightCoral"
                                    Name="nonBillable" BorderColor="180, 26, 59, 105" CustomProperties="DrawingStyle=Cylinder" ShadowColor="Transparent">
                                </asp:Series> --%>
                            </series>
                            <chartareas>
                                <asp:ChartArea Name="ChartArea1"  BorderColor="64, 64, 64, 64" BackSecondaryColor="White" BackColor="#EFE6F7" ShadowColor="DarkRed" BackGradientStyle="TopBottom">
                                    <area3dstyle Rotation="10" Perspective="10" Inclination="15" IsRightAngleAxes="False" WallWidth="0" IsClustered="False" />
                                    <axisy LineColor="64, 64, 64, 64"  LabelAutoFitMaxFontSize="8" Title="Hours">
                                        <LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold"  />
                                        <MajorGrid LineColor="64, 64, 64, 64" />
                                    </axisy>
                                    <axisx LineColor="64, 64, 64, 64"  LabelAutoFitMaxFontSize="8" Title="Members">
                                        <LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" IsEndLabelVisible="False"  />
                                        <MajorGrid LineColor="64, 64, 64, 64" />
                                    </axisx>
                                </asp:ChartArea>
                            </chartareas>
                        </asp:CHART>
  
    </div>
    </form>
</body>
</html>


---------------------------------------------------------------------------------------------------------
C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml.Linq;
using System.Collections;
using System.Drawing;
using System.Web.UI.DataVisualization.Charting;
using System.Globalization;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {



        foreach (Series series in this.Chart1.Series)
        {
            // this.Chart1.Series[2].PostBackValue = "#INDEX";
            series.PostBackValue = "#INDEX";

        }

        Chart1.Series.Add("Billable");
        Chart1.Series["Billable"].ChartType = SeriesChartType.StackedColumn;
        Chart1.Series["Billable"].IsValueShownAsLabel = true;
        this.Chart1.Series[1].PostBackValue = "#INDEX";

        Chart1.Series.Add("nonBillable");
        Chart1.Series["nonBillable"].ChartType = SeriesChartType.StackedColumn;
        Chart1.Series["nonBillable"].IsValueShownAsLabel = true;
        this.Chart1.Series[2].PostBackValue = "#INDEX";

        Chart1.Series.Add("walia");
        Chart1.Series["walia"].ChartType = SeriesChartType.StackedColumn;
        Chart1.Series["walia"].IsValueShownAsLabel = true;
        this.Chart1.Series[3].PostBackValue = "#INDEX";

       Chart1.Series["Billable"].Points.AddY(37);
        Chart1.Series["nonBillable"].Points.AddY(40);
        Chart1.Series["walia"].Points.AddY(47);

        Chart1.Series["Billable"].Points.AddY(13);
        Chart1.Series["nonBillable"].Points.AddY(22);
        Chart1.Series["walia"].Points.AddY(43);

        Chart1.Series["Billable"].Points.AddY(11);
        Chart1.Series["nonBillable"].Points.AddY(41);
        Chart1.Series["Billable"].Points.AddY(1);

        Chart1.Series["nonBillable"].Points.AddY(40);
        Chart1.Series["Billable"].Points.AddY(10);
        Chart1.Series["nonBillable"].Points.AddY(40);
        Chart1.Series["Billable"].Points.AddY(16);

        Chart1.Series["nonBillable"].Points.AddY(106);
        Chart1.Series["Billable"].Points.AddY(16);
        Chart1.Series["nonBillable"].Points.AddY(24);
        Chart1.Series["Billable"].Points.AddY(21);

        Chart1.Series["nonBillable"].Points.AddY(24);
        Chart1.Series["Billable"].Points.AddY(21);
        Chart1.Series["nonBillable"].Points.AddY(24);


        //Chart1.Series["Billable"].Points.DataBindXY("CarBrand", "CarCount");
         Chart1.Series["Billable"].Points[0].AxisLabel = "Tom";
         Chart1.Series["Billable"].Points[1].AxisLabel = "Richard";
         Chart1.Series["Billable"].Points[2].AxisLabel = "Harry";

         Chart1.Series["Billable"].Points[3].AxisLabel = "walia";
         Chart1.Series["Billable"].Points[4].AxisLabel = "sachin";
         Chart1.Series["Billable"].Points[5].AxisLabel = "rahul";

         Chart1.Series["Billable"].Points[6].AxisLabel = "gandhi";
         Chart1.Series["Billable"].Points[7].AxisLabel = "cricket";
         Chart1.Series["Billable"].Points[8].AxisLabel = "socker";
    }
    protected void Chart1_Click(object sender, ImageMapEventArgs e)
    {
        string a = e.PostBackValue;
        Response.Write(a);
    }
}

No comments:

Post a Comment