3
내가있는 개체를 가지고Linq에 선택 제품 수 년 카테고리
아래처럼 구글 막대 그래프 플롯하려고에 따라
나는var grouped = (
from c in allCategories
from p in allProducts
group p by new { year = p.CreateDate.Year} into d
select new { year = d.Key.year, count = d.Count()}).OrderByDescending(g => g.year).Distinct();
<script type="text/javascript">
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Category Name', '2006', '2011', '2013'],
@foreach (var p in grouped)
{
int productThisYear = grouped.Where(x => x.year <= p.year).Select(x => x.count).Sum();
<text>
['', @productThisYear,@productThisYear,@productThisYear]
</text>
if(counter++ != grouped.Count() - 1){
@Html.Raw(",")
}
}
]);
var options = {
title: 'Product Categories',
hAxis: { title: '' }
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
과 같은 코드를 시도
product
{
id,
name,
categoryid
}
category
{
id,
categoryname
}
하지만 범주 이름과 제품 수를이 범주 이름과 연도를 기반으로 가져올 수 없습니다. 어떤 문제가 발생할 수 있습니까? 도움에 미리 감사합니다 ..