【发布时间】:2016-01-29 05:02:45
【问题描述】:
我的问题是针对: Showing System.Web.Helpers.Chart in a partial view from the model
@{
var myChart = new Chart(width: 600, height: 400)
.AddTitle("Chart Title")
.AddSeries(
name: "Employee",
xValue: new[] { "Peter", "Andrew", "Julie", "Mary", "Dave" },
yValues: new[] { "2", "6", "4", "5", "3" })
.Write();
}
有没有人能够在 xValue 和 yValue 中使用循环中的值。目前在示例中,我发现所有值都是硬编码的。
我想使用下面 foreach 语句中的 item.season 作为 X 和 item.year 作为 Y(第一次收集主题,第二次收集年份和季节):
string json2 = File.ReadAllText(@"C:\Temp\Assess.json");
var root = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<List<WebApplication1.Models.SchoolSubject>>(json2);
foreach (var subject in root)
{
<h2>@Html.Raw(subject.Subject)</h2>
foreach (var item in subject.AppScores)
{
<p>@Html.Raw(item.Season)</p>
<p>@Html.Raw(item.year)</p>
<p>@Html.Raw(item.value)</p>
}
}
包含类代码的模型:
public class SchoolSubjectAppScore
{
public string Season { get; set; }
public string year { get; set; }
public string value { get; set; }
}
public class SchoolSubject
{
public SchoolSubject() { this.AppScores = new List<SchoolSubjectAppScore>(); }
public string Subject { get; set; }
public List<SchoolSubjectAppScore> AppScores { get; set; }
}
我拥有的 JSON 文件是:
[{"Subject": "English","AppScores": [{"Season": "Winter","year": "2009", "value" : "20" }, {"Season": "Summer","year": "2009", "value" : "38"}]}, {"Subject": "Maths","AppScores": [{"Season": "Winter","year": "2009", "value" : "10"}, {"Season": "Summer","year": "2009", "value" : "27"}]}]
我想要的图表上的输出是两个系列 - 数学/英语,xValue - Season/Year 和 yValue - Value。
任何想法,因为我到处寻找帮助。
【问题讨论】:
标签: c# asp.net asp.net-mvc loops charts