I also encountered the same problem with you,just did a project on morris example,I hope to help you.
<body>
<div>
Morris
<div id="myfirstchart" style="height: 250px; " >
</div>
</div>
</body>
</html>
<script type="text/javascript">
new Morris.Line({
element: 'myfirstchart',
data: @ViewBag.jss ,
xkey: 'year',
ykeys: ['value','a','b'],
labels: ['Value','This A','this B']
});
</script>
<pre lang="c#"> public ActionResult Morris()
{
LineDemo lineDemo1 = new LineDemo();
lineDemo1.year="2008";
lineDemo1.value = 20;
lineDemo1.a=30;
lineDemo1.b=15;
LineDemo lineDemo2 = new LineDemo();
lineDemo2.year = "2009";
lineDemo2.value = 30;
lineDemo2.a = 40;
lineDemo2.b = 20;
LineDemo lineDemo3 = new LineDemo();
lineDemo3.year = "2010";
lineDemo3.value = 40;
lineDemo3.a = 50;
lineDemo3.b = 30;
LineDemo lineDemo4 = new LineDemo();
lineDemo4.year = "2011";
lineDemo4.value = 25;
lineDemo4.a = 35;
lineDemo4.b = 55;
List<LineDemo> listLine = new List<LineDemo>();
listLine.Add(lineDemo1);
listLine.Add(lineDemo2);
listLine.Add(lineDemo3);
listLine.Add(lineDemo4);
JavaScriptSerializer jss = new JavaScriptSerializer();
string output = jss.Serialize(listLine);
string demo = output.Replace("\"", "");
ViewBag.jss = demo;
return View();
}
}
public class LineDemo
{
public string year{get;set;}
public int value{get;set;}
public int a{get;set;}
public int b{get;set;}
}
The data transport by Json, It should be noted that Json' Key have quotation ,you must delete it,you can use Regular Expression . this is asp.net MVC. My English is not good.Hope you can understand.