我有以下SQL Server结果。 如何使用asp.net 4图表控件创建堆积柱形图?
Hospital September October April
OMD 10 20 15
IRH 15 16 18
这样的事情:
答案 0 :(得分:0)
以下是一个例子:
<强> ASPX:强>
<asp:Chart ID="chart1" runat="server">
<Series>
<asp:Series Name="Series1" Label="September"></asp:Series>
<asp:Series Name="Series2" Label="October"></asp:Series>
<asp:Series Name="Series3" Label="April"></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1"></asp:ChartArea>
</ChartAreas>
</asp:Chart>
<asp:Button ID="Button1" runat="server" Text="Graph" onclick="Button1_Click" />
C#Code-Behind:
protected void Button1_Click(object sender, EventArgs e)
{
// September Data
Chart1.Series[0].Points.Add(new DataPoint(0, 10));
Chart1.Series[0].Points.Add(new DataPoint(1, 15));
// October Data
Chart1.Series[1].Points.Add(new DataPoint(0, 20));
Chart1.Series[1].Points.Add(new DataPoint(1, 16));
// April Data
Chart1.Series[2].Points.Add(new DataPoint(0, 15));
Chart1.Series[2].Points.Add(new DataPoint(1, 18));
foreach (Series cs in chart1.Series)
cs.ChartType = SeriesChartType.StackedColumn;
}
或者使用SQL数据源 ds ,您可以直接执行以下操作:
DataTable dt = new DataTable();
dt = ds.Tables[0];
DataView dv = new DataView(dt);
chart1.DataSource = dv;
chart1.DataBind();
foreach (Series cs in chart1.Series)
cs.ChartType = SeriesChartType.StackedColumn;