数据库列中的总值,并在图表ASP.net中显示

时间:2018-05-13 16:16:32

标签: asp.net asp.net-mvc

我想总结一下我的图表的数量列的值。

var db = Database.Open("OrdersContext");
var data = db.Query("SELECT ProductId,Quantity  FROM OrderDetails");
var myChart = new Chart(width: 600, height: 400, theme: ChartTheme.Green)


   .AddTitle("Product Sales")
   .AddSeries("Default",
xValue: data, xField: "ProductId",
yValues: data, yFields:"Quantity")
    .Write();

enter image description here

1 个答案:

答案 0 :(得分:0)

试试此代码

var db = Database.Open("OrdersContext");
var data = db.Query("SELECT ProductId, SUM(Quantity) TotalQuantity FROM OrderDetails Group By ProductId");
var myChart = new Chart(width: 600, height: 400, theme: ChartTheme.Green)


   .AddTitle("Product Sales")
   .AddSeries("Default",
xValue: data, xField: "ProductId",
yValues: data, yFields:"TotalQuantity")
    .Write();

此查询将为您提供每个产品数量的总和