我有这个功能
public ActionResult GetChartImage()
{
var key = new Chart(width: 300, height: 300)
.AddTitle("Employee Chart")
.AddSeries(
chartType: "Bubble",
name: "Employee",
xValue: new[] { "Peter", "Andrew", "Julie", "Dave" },
yValues: new[] { "2", "7", "5", "3" });
return File(key.ToWebImage().GetBytes(), "image/jpeg");
}
这将从静态数据创建图表。
如果我的数据库包含名为Employee的表以及功能Name
和Satisfunction
。
问题:如何转换上述功能以返回包含动态数据的图表?我对C#没有任何经验以及它是如何工作的。
答案 0 :(得分:1)
在行动中我有:
///Get data from db
var articles = _db.Articles
.OrderByDescending(a => a.Visites)
.Take(6)
.ToList();
//create chart note xValue i m passing my articles as data to this
// xFiled witch is set to Title is a property on my article class
var chart = new Chart(520, 340, theme: ChartTheme.Blue)
.AddTitle("Most visited articles")
.AddSeries(name: "Default",
xValue: articles, xField: "Title", chartType: "StackedColumn",
yValues: articles, yFields: "Visites")
.GetBytes("png");
return File(chart, "image/png");