c#如何使用Linq显示图表Y值标签

时间:2019-02-09 12:40:11

标签: c# linq charts

enter image description here 我在FormLoad事件中具有以下Linq代码:

ShowChartReport();

            chart1.Series.Clear();

            var series = chart1.Series.Add("Series1");
            series.XValueMember = "ProduktId";
            series.YValueMembers = "TolatlSold"; 
            series.Name = "Products";
            chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;

然后是下面的图表上传方法

private void ShowChartReport()
        {
            using (CoffeEntities db = new CoffeEntities())
            {
                var result = (from pr in db.SaleDetails
                              group pr by pr.Product.Description into g
                              select new
                              {
                                  ProduktId = g.Key,
                                  TolatlSold = g.Count()


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

            }
        }

我在ShowChartReport()中甚至尝试过这种方式

chart1.Series["ProduktId"].IsValueShownAsLabel = true;
chart1.Series["TolatlSold"].IsValueShownAsLabel = true;

但是直到现在我都无法在每个图表元素中看到那些Y值标签。

就像这个问题how to display values on chart graph using c#  我想要但我正在使用Linq并使我感到困惑。该怎么办...如果您能帮助我,我将不胜感激

0 个答案:

没有答案