c#Windows窗体,如何从数据库中显示图表中的数据

时间:2019-06-24 21:07:03

标签: c# winforms charts

enter image description here

enter image description here

您好,我想在图表中显示已售出的鞋子数量。我有四个表,例如tblCategory,tblProduct,tblTransaction和tblTransactionItem。 我分为三个类别(如您在图片中看到的那样,是MenShose,WemanShose和KiddsShose) 我想在X轴上显示类别名称和颜色大小,例如Wemanshose-35,“ WomenShe是categoryName,35是颜色大小”。

何时 我尝试过这种方法,但显示出错误的结果。

public DisplaySales()
        {
            InitializeComponent(); 
            chart1.Series.Clear();

            var series = chart1.Series.Add("Series1");
            series.XValueMember = "ProduktId";
            series.YValueMembers = "TolatlSold";
            series.Name = "Shose";
            chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;
            chart1.Series["Shose"].IsValueShownAsLabel = true;
            series.CustomProperties = "LabelStyle=Left";

            ShowTodaysSoldProduct();


        }
// And here is what I'am trying but shows me wrong result. Please Help!


   private void ShowTodaysSoldProduct()
    {
        using (Db db = new Db())
        {
            DateTime today = DateTime.Today;
            DateTime tomorrow = today.AddDays(1);
            var result = (from tr in db.TransactionItems
                          join t in db.Transactions on tr.TransactionId equals t.TransactionId
                          //join p in db.Products on tr.ProductId equals p.ProductId
                          join c in db.Categories on tr.CategoryId equals c.CategoryId
                          where t.TransactionDate >= today && t.TransactionDate < tomorrow
                          group tr by tr.categories.CategoryName  into g
                          select new ProductSaled
                          {
                              ProduktId =  g.Key, // Before g.Key I want to display CategoryName too 
                              TolatlSold = g.Count()

                          }).ToList();
            chart1.DataSource = result;

            chart1.DataBind();
            chart1.Show();

        }
    }

我真的不知道如何将它们分组

0 个答案:

没有答案