从DataTable动态创建Box Plot图表

时间:2015-09-26 18:48:02

标签: c# asp.net data-binding charts datatable

我想根据数据表中的数据创建箱形图。我能够从datatable动态创建柱形图,但我想创建箱形图和柱形图。

这是我的代码:

Aspx文件:

<asp:Chart ID="Chart1" runat="server">

                <Series>

                </Series>

                <ChartAreas>

                </ChartAreas>

            </asp:Chart>

Cs文件:

 public void BindChart()
    { 
        DataTable tg = new DataTable();
        DataRow dr;
        tg.Columns.Add(new DataColumn("DATE"));
        tg.Columns.Add(new DataColumn("CODE"));
        tg.Columns.Add(new DataColumn("PERSON_NAME"));
        tg.Columns.Add(new DataColumn("STATUS"));
        tg.Columns.Add(new DataColumn("HOBBIES"));
        tg.Columns.Add(new DataColumn("SCORE"));
        tg.Columns.Add(new DataColumn("ITEM"));
        tg.Columns.Add(new DataColumn("QUANTITY"));
        tg.Columns.Add(new DataColumn("TYPE"));
        tg.Columns.Add(new DataColumn("RATING"));
        tg.Columns.Add(new DataColumn("PRODUCT"));
        foreach (GridViewRow gvr in GridView1.Rows)
        {
            if (gvr.Cells[3].Text == "Regular")
            {
                dr = tg.NewRow();
                dr["DATE"] = gvr.Cells[0].Text;
                dr["CODE"] = gvr.Cells[1].Text;
                dr["PERSON_NAME"] = gvr.Cells[2].Text;
                dr["STATUS"] = gvr.Cells[3].Text;
                dr["HOBBIES"] = gvr.Cells[4].Text;
                dr["SCORE"] = gvr.Cells[5].Text;
                dr["ITEM"] = gvr.Cells[6].Text;
                dr["QUANTITY"] = gvr.Cells[7].Text;
                dr["TYPE"] = gvr.Cells[8].Text;
                dr["RATING"] = gvr.Cells[9].Text;
                dr["PRODUCT"] = gvr.Cells[10].Text;
                tg.Rows.Add(dr);

            }
        }
        Chart1.DataSource = tg;
        Chart1.Width = 600;
        Chart1.Height = 350;
        //create series
        Series serie1 = new Series();
        serie1.Name = "Serie1";
        serie1.ChartType = SeriesChartType.BoxPlot;
        serie1.IsValueShownAsLabel = true;
        serie1.Points.AddY(6);
        serie1.XValueMember = "PRODUCT";
        serie1.YValueMembers = "ITEM";

        Chart1.Series.Add(serie1);
        string Title = (tg.Rows[0]["Status"].ToString());
        Chart1.Titles.Add(Title);
        //create chartareas...
        ChartArea ca = new ChartArea();
        ca.Name = "ChartArea1";
        ca.AxisX = new Axis();
        ca.AxisY = new Axis();
        Chart1.ChartAreas.Add(ca);
        //databind
        Chart1.DataBind();
        Chart1.Visible = true;
}

问题:根据我的代码,我可以从datatable动态创建柱形图。如何从数据表动态创建箱形图

感谢有人可以帮我解决这个问题。非常感谢!!

0 个答案:

没有答案