0

I am working in .Net Charts. I am trying to generate a Column chart. I am having two rows in my dataset. Here is my code.

                    DataTable DT1 = new DataTable();
                    DT1 = chartViewSummaryList;
                    DataView DV = DT1.DefaultView;
                    DV.ToTable(false, new string[] { "REVENUE_TOTAL", "WEEK_END_DATE" });

                    DataSet ds = new DataSet();
                    ds.Tables.Add(DT1.Copy());

                    ds.Tables[0].Rows[0]["MARGIN"] = "0";
                    ds.Tables[0].Rows[0]["REVENUE_TOTAL"] = "3776169.61";
                    ds.Tables[0].Rows[0]["MARGIN_PCT"] = "0";
                    ds.Tables[0].Rows[0]["VISIT_REVENUE_AVG"] = "29.28";
                    ds.Tables[0].Rows[0]["VISIT_COUNT"] = "614041";
                    ds.Tables[0].Rows[0]["REVENUE_SALE"] = "1840387.18";
                    ds.Tables[0].Rows[0]["REVENUE_REGULAR"] = "1935782.43";
                    ds.Tables[0].Rows[0]["WEEK_END_DATE"] = "1/1/2012 12:00:00 AM";

                    ds.Tables[0].Rows.Add();

                    ds.Tables[0].Rows[1]["MARGIN"] = "1";
                    ds.Tables[0].Rows[1]["REVENUE_TOTAL"] = "5776169.61";
                    ds.Tables[0].Rows[1]["MARGIN_PCT"] = "0";
                    ds.Tables[0].Rows[1]["VISIT_REVENUE_AVG"] = "49.28";
                    ds.Tables[0].Rows[1]["VISIT_COUNT"] = "814041";
                    ds.Tables[0].Rows[1]["REVENUE_SALE"] = "3840387.18";
                    ds.Tables[0].Rows[1]["REVENUE_REGULAR"] = "3935782.43";
                    ds.Tables[0].Rows[1]["WEEK_END_DATE"] = "1/1/2012 12:00:00 AM";



                    Chart1.DataSource = ds;

                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        Chart1.Titles.Add(storeLevelCaption).Font = new System.Drawing.Font("Verdana", 11, FontStyle.Bold);
                        Chart1.ChartAreas["ChartArea1"].AxisX.Title = "Weeks";
                        Chart1.ChartAreas["ChartArea1"].AxisX.TitleFont = new System.Drawing.Font("Verdana", 10, FontStyle.Bold);
                        Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font(new FontFamily("Verdana"), 7.25F, FontStyle.Bold);
                        string series = "Series" + i;
                        Chart1.Series.Add(series);

                        Chart1.Series[series].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Column;

                        Chart1.Series[series].XValueMember = "WEEK_END_DATE";
                        Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;

                        Color color = System.Drawing.ColorTranslator.FromHtml("#B93B8F");
                        Chart1.Series[series].Color = color;

                        Chart1.ChartAreas["ChartArea1"].AxisY.Title = "Total Revenue";
                        Chart1.ChartAreas["ChartArea1"].AxisY.TitleFont = new System.Drawing.Font("Verdana", 10, FontStyle.Bold);
                        Chart1.ChartAreas["ChartArea1"].AxisY.LabelStyle.Font = new Font(new FontFamily("Verdana"), 7.25F, FontStyle.Bold);
                        Chart1.Series[series].YValueMembers = "REVENUE_TOTAL";
                        Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false;

                        Chart1.Series[series].ToolTip = "Total Revenue ($) , " + ds.Tables[0].Rows[i]["WEEK_END_DATE"].ToString() + " , " + ds.Tables[0].Rows[i]["REVENUE_TOTAL"].ToString();

                        Chart1.Series[series].Font = new Font(new FontFamily("Verdana"), 7.25F, FontStyle.Bold);
                        //Chart1.Series[series].Name = "Total Revenue";
                    }
                    Chart1.ChartAreas[0].AxisY.Interval = 1;
                    Chart1.DataBind();

I am getting the chart, where two column combined together and displayed as one column. Where i had gone wrong...

4

1 回答 1

0

我无法使用 WinForm 图表程序集重现您的问题。但是,您可能想尝试使用不同的日期,因为它们绑定到您的 X 值。

ds.Tables[0].Rows[0]["WEEK_END_DATE"] = "1/1/2012 12:00:00 AM";
ds.Tables[0].Rows[1]["WEEK_END_DATE"] = "8/1/2012 12:00:00 AM"; // a different date

仅供参考,我对您的代码进行了最低限度的更改

        // DT1 = chartViewSummaryList;
        // replace unknown object with this code
        DT1.Columns.Add(new DataColumn("MARGIN"));
        DT1.Columns.Add(new DataColumn("REVENUE_TOTAL"));
        DT1.Columns.Add(new DataColumn("MARGIN_PCT"));
        DT1.Columns.Add(new DataColumn("VISIT_REVENUE_AVG"));
        DT1.Columns.Add(new DataColumn("VISIT_COUNT"));
        DT1.Columns.Add(new DataColumn("REVENUE_SALE"));
        DT1.Columns.Add(new DataColumn("REVENUE_REGULAR"));
        DT1.Columns.Add(new DataColumn("WEEK_END_DATE"));

并且还手动添加了一行

        ds.Tables.Add(DT1.Copy());
        ds.Tables[0].Rows.Add(); // Added this

并从您的绘图代码中得到两列。

于 2012-09-12T12:50:49.787 回答