【发布时间】:2011-11-16 11:39:00
【问题描述】:
我想使用下面的代码在 mvc 3 razor 中创建一个图形图表(感谢 DotNetJalps):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Helpers;
namespace CodeSimplifiedTest.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
public ActionResult About()
{
return View();
}
public ActionResult DrawChart()
{
var chart = new Chart(width: 300, height: 200)
.AddSeries(
chartType: "bar",
xValue: new[] { "10 Records", "20 Records", "30 Records", "40 Records" },
yValues: new[] { "50", "60", "78", "80" })
.GetBytes("png");
return File(chart, "image/bytes");
}
}
}
但是
我想从 SQL Server 2008 R2 数据库中检索 xValues 和 Yvalues...我必须在 xValue: 和 yValue: 之后放置什么代码,或者在控制器和视图中的任何位置放置一些代码才能从数据库中检索数据?我尝试了实体框架上下文...但它不起作用。
谢谢
【问题讨论】:
-
这取决于您的表架构、您的数据在此 SQL 数据库中的组织方式以及您希望使用的数据访问技术。
标签: asp.net-mvc-3 charts razor helpers