Highcharts在单个页面上使用c#asp.net mvc3的多个图表 [英] Highcharts multiple charts on a single page using c# asp.net mvc3
问题描述
我想知道是否可以使用c#将多个图表返回到单个页面/视图?
背景信息
I was wondering if it was possible to return multiple charts to a single page/view using c#?
Background Information
- ASP.NET MVC3
- DotNet.Highcharts库
目标:我的总体目标是使用ASP.NET MVC3创建一个包含两个图表的网页
Goal: My overall goal is to have a webpage with two charts using ASP.NET MVC3
示例
HighCharts g1 = new HighCharts("chart");
HighCharts g2 = new HighCharts("chart");
return View(model, g1, g2);
这是我想要的示例,但我不太确定如果这是可能的。如果是这样,我将如何实现这一目标?如果可能,我如何使用剃刀输出图表?
This is an example of what I want, but I am not too sure if this is possible. If so how would I accomplish this? If possible how would I output the charts using razor?
非常感谢您的帮助,我很感激!
Thank you so much for the help, I appreciate it! Please let me know if there are any misunderstandings in the question.
推荐答案
只要创建一个拥有列表< HighChart>
(或将其添加到现有模型)。例如:
Just create a model that holds a List<HighChart>
(or add it to your existing model). Something like:
public class ChartsModel
{
public List<HighChart> Charts { get; set; }
}
然后,您可以填充模型并将其发送到您的操作中的视图方法,像这样:
Then you can populate the model and send it to the view in your action method, like so:
ChartsModel model = new ChartsModel();
model.Charts = new List<HighChart>();
HighCharts g1 = new HighCharts("chart");
HighCharts g2 = new HighCharts("chart");
model.Charts.Add(g1);
model.Charts.Add(g2);
return View(model);
然后在视图中,您可以循环每个图表:
Then in your view, you can loop round each chart:
@model ChartsModel
@foreach (HighCharts chart in Model.Charts)
{
@* do your stuff *@
}
这篇关于Highcharts在单个页面上使用c#asp.net mvc3的多个图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!