Reputation: 31
I want to create Stacked Column Chart using ASP.NET, C#.
Can you give me examples to develop stacked column bar chart. And the series values are shown in bar, count at the top side of the bar. I am new to develop chart in dotnet.
Can anyone suggest me, how can I achieve this.
Would appreciate url's where can I find the demo to do this completely.
Upvotes: 3
Views: 7014
Reputation: 903
you may use following code First add chart in aspx page as following:
<asp:Chart ID="Chart1" runat="server" Width="500px">
<Series>
<asp:Series Name="Series1" ChartType="StackedBar"></asp:Series>
</Series>
<Series>
<asp:Series Name="Series2" ChartType="StackedBar"></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1"></asp:ChartArea>
</ChartAreas>
</asp:Chart>
Then write following code:
using (SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString))
{
cnn.Open();
SqlDataAdapter da = new SqlDataAdapter("select MonthName,TotalTruck,Item from table1", cnn);
DataTable dt = new DataTable();
da.Fill(dt);
Chart1.DataSource = dt;
Chart1.Series[0].XValueMember = "MonthName";
Chart1.Series[0].YValueMembers = "TotalTruck";
Chart1.Series[1].XValueMember = "Item";
Chart1.Series[1].YValueMembers = "TotalTruck";
Chart1.DataBind();
}
}
It will stack Item in the bars.
Upvotes: 1