我正在尝试显示一个条形图(来自Google Charts),该条形图应显示每个学院的提交数量(计数)。在该系列中,该计数分为4种提交类型(书籍,章节,期刊和会议)。当我运行报告时<我收到一个错误,返回我的查询。我无法弄清楚我哪里出错了
@using WebMatrix.Data;
@using WebMatrix.WebData;
@{
ViewBag.Title = "Report_2";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@{
var db = Database.Open("RMSContext");
String rows = "";
var Query = ("SELECT Faculty.FacultyName, Submission.Type, Count(Submission.SubmissionID) AS CountOfSubmissionID FROM Submission INNER JOIN ((Faculty INNER JOIN School ON Faculty.FacultyID = School.[FacultyID]) INNER JOIN (Researcher INNER JOIN ResearcherSubmission ON Researcher.ResearcherID = ResearcherSubmission.ResearcherID) ON School.SchoolID = Researcher.SchoolID) ON Submission.SubmissionID = ResearcherSubmission.SubmissionID GROUP BY Faculty.FacultyName, Submission.Type;");
var AppQuery = db.Query(Query);
List<string> rowsList = new List<string>();
foreach (var item in AppQuery)
{
rowsList.Add("['" + item.FacultyName + "', " + item.Type + "', " + item.CountOfSubmissionID + "]");
};
rows = String.Join(", ", rowsList);
}
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1.1", { packages: ["bar"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var data1 = google.visualization.arrayToDataTable([
['FacultyName', 'Type', 'SubmissionID'],
@Html.Raw(rows)]);
var options = {
title: ''
};
var chart = new google.charts.Bar(document.getElementById('columnchart_material'));
chart.draw(data1, options);
}
</script>
<div id="columnchart_material" style="width: 800px; height: 500px;"></div>
以下是我的报告应该如何看的模拟:
答案 0 :(得分:1)
您需要重新格式化数据,因为我在此处进行了硬编码...
google.load("visualization", "1.1", {packages:["bar"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Faculty', 'Journal Articles', 'Books', 'Book Chapters', 'Conference'],
['CLM', 3, 5, 1, 2],
['EBE', 0, 1, 2, 4],
['Health Sciences', 3, 3, 5, 2],
['Humanities', 1, 4, 2, 2],
['Science', 1, 1, 2, 1]
]);
var options = {
chart: {
title: 'Faculty Submissions',
subtitle: 'Types of research provided'
}
};
var chart = new google.charts.Bar(document.getElementById('columnchart_material'));
chart.draw(data, options);
}