MVC最好的方式来显示图表
问题描述:
我是新手,现在我试图显示与MVC的图表。MVC最好的方式来显示图表
有两种可能性,以显示图表:
- System.Web.UI.DataVisualization.Charting.Chart
- System.Web.Helpers.Chart
这是这两种解决方案之间的不同?和之间的优势/劣势是什么?
目前,我试试这个代码:
控制器:
[HttpPost]
public ActionResult RenderRainfallChart()
{
var incomeList = Income.GetList();
List<string> xValue = new List<string>();
List<decimal> yValue = new List<decimal>();
foreach (var item in incomeList)
{
xValues.Add(item.Name);
yValues.Add(item.Amount);
}
var key = new System.Web.Helpers.Chart(width: 600, height: 400)
.AddSeries(
legend: "IncomeLIst",
xValue: xValue,
yValues: yValues)
.Write();}
我的按钮选择后,该图表将显示一个新的broswer页面上:... /公司/ RenderRainfallChart
是否有可能在索引网站上的div容器中显示图表?
答
Google图表API可能?它使用JavaScript,因此您必须在页面中写入值或使用AJAX检索它们。
答
对于一个非交互式图表,您可以让一个GET获取图表的图像,然后在您的网页上,您可以简单地将一个<img>
指向该URL。
你可以使用这样的图表图像字节:
byte[] GetBytes(Chart chart, ChartImageFormat imageFormat)
{
using (var stream = new MemoryStream())
{
chart.SaveImage(stream, imageFormat);
return stream.ToArray();
}
}
但对于谷歌图表API,我需要一个互联网连接,还是? – NimraF 2012-08-07 13:39:50
您与MVC合作不? 99%的时间服务器将具有活动的Internet连接 – 2012-08-07 13:59:47