C# ASP.NET MVC Razor中的多个图表

C# ASP.NET MVC Razor中的多个图表,c#,asp.net,asp.net-mvc,razor,charts,C#,Asp.net,Asp.net Mvc,Razor,Charts,我的控制器代码: public ActionResult Index() { Session["GetAllChart"] = GetAllCharts(); return View(); } public List<Chart> GetAllCharts(int patientId = 1) { List<Chart> allCharts = new List<Chart>(); for

我的控制器代码:

public ActionResult Index()
{
        Session["GetAllChart"] = GetAllCharts();
        return View();
}
public List<Chart> GetAllCharts(int patientId = 1)
    {
        List<Chart> allCharts = new List<Chart>();
        foreach (PatientConditionColumnName patientConditionColumnName in patientConditionBll.GetPatientColumnNameList())
        {
            allCharts.Add(GetChart(patientId, patientConditionColumnName.ColumnName));
        }
        return allCharts;
    }

public Chart GetChart(int patientId, string parameter)
    {
        ArrayList xValue = new ArrayList();
        ArrayList yValue = patientConditionBll.GetYValues(patientId, parameter);

        List<PatientCondition> patientConditionAll = context.PatientConditions.Where(m => m.PatientId == patientId).ToList();
        patientConditionAll.ForEach(m => xValue.Add(m.time));

        Chart chart = new Chart(width: 600, height: 400, theme: ChartTheme.Blue)
            .AddTitle("y axis represents " + parameter + " value")
            .AddLegend("x axis represents time")
            .AddSeries("Default", chartType: "Line", xValue: xValue, yValues: yValue);


        return chart;
    }
public ActionResult Index()
{
会话[“GetAllChart”]=GetAllCharts();
返回视图();
}
公共列表GetAllCharts(int patientId=1)
{
List allCharts=新列表();
foreach(PatientConditionColumnName PatientConditionColumnName位于patientConditionBll.GetPatientColumnNameList()中)
{
添加(GetChart(patientId,patientConditionColumnName.ColumnName));
}
返回所有图表;
}
公共图表GetChart(int patientId,字符串参数)
{
ArrayList xValue=新的ArrayList();
ArrayList yValue=patientConditionBll.GetyValue(patientId,参数);
列出PatientConditional=context.PatientConditions.Where(m=>m.PatientId==PatientId.ToList();
PatientConditional.ForEach(m=>xValue.Add(m.time));
图表=新图表(宽度:600,高度:400,主题:ChartTheme.Blue)
.AddTitle(“y轴表示“+参数+”值”)
.AddLegend(“x轴代表时间”)
.AddSeries(“默认”,图表类型:“线”,xValue:xValue,yValue:yValue);
收益表;
}
在Index.cshtml中

@{
  List<Chart> chartsAll = Session["GetAllChart"] as List<Chart>;}


<div class="col-md-4">
    <section id="showChart">

        @if (chartsAll != null)
        {
                foreach (var aChart in chartsAll)
                {
                    <div> @aChart.Write(format: "png")</div>
                }
        }

    </section>
@{
List chartsAll=会话[“GetAllChart”]作为列表;}
@if(chartsAll!=null)
{
foreach(chartsAll中的var aChart)
{
@aChart.Write(格式:“png”)
}
}
这里几乎有29个参数,我想显示每个参数(如HR、尿液、总摄入量)相对于时间的单独图表。但仅显示第一张Spo2图表。 如何在页面中显示与时间相关的所有参数单个图表的列表? 我的源代码下载,包括数据库:

尝试以下操作:

@{
    List<Chart> chartsAll = Session["GetAllChart"] as List<Chart>;
}


<div class="col-md-4">
    <section id="showChart">

        @if (chartsAll != null)
        {
            int i = 1;
            foreach (var aChart in chartsAll)
            {
                string name = string.Format("~/Content/Chart{0}.png", i++);
                aChart.Save(name);
                <img src="@Url.Content(name)" alt="@name" />
            }
        }

    </section>
</div>
@{
列表图表sall=会话[“GetAllChart”]作为列表;
}
@if(chartsAll!=null)
{
int i=1;
foreach(chartsAll中的var aChart)
{
string name=string.Format(“~/Content/Chart{0}.png”,i++);
aChart.Save(名称);
}
}

有人帮我解决问题吗?非常感谢你的帮助。但在我的项目中,图表显示在一列而不是一行中。这取决于浏览器窗口的宽度/高度,请更改它,然后查看发生了什么。这解决了问题。你可以推荐一些其他的文章或资源,从中我可以了解更多关于图表的信息吗。