You can have a viewmodel that represents your data, then build a collection of it in your controller. You can then call it via ajax and return it as a json object.
The ViewModel
public class YearlyStat {
public int Year {get;set;}
public int Value {get;set;}
}
Build the data in the controller like this:
public ActionResult Statistics() {
// most probably the values will come from a database
// this is just a sample to show you
// that you can return an IEnumerable object
// and it will be serialized properly
var stats = new List<YearlyStat> {
new YearlyStat { Year=2008, Value=20},
new YearlyStat { Year=2009, Value=10},
}
return Json(stats,JsonRequestBehavior.AllowGet);
}
Then consume it like this:
$.get('@Url.Action("Statistics")', function(result){
new Morris.Line({
data: result,
});
});