Click here to Skip to main content
14,984,043 members
Please Sign up or sign in to vote.
1.55/5 (6 votes)
See more:
I want data in
[ { a : 100,
y : 2006
},
{ "a" : 75,
"y" : 2007
},
{ "a" : 50,
"y" : 2008
},
{ "a" : 75,
"y" : 2009
},
{ "a" : 50,
"y" : 2010
},
{ "a" : 75,
"y" : 2011
},
{ "a" : 100,
"y" : 2012
}
]

this format for morris graphs and charts.
Thanks in advance..
Posted
Updated 5-Apr-14 12:32pm
v2
Comments
ZurdoDev 5-Apr-14 18:22pm
   
That's not a question nor does it tell us where you are stuck.

1 solution

hi this is JSON format. try WCF to get data in JSON.
   
Comments
Vedant Dave 6-Apr-14 2:16am
   
I created Jsfiddle i want that output.
http://jsfiddle.net/Y3Cf9/

My Json format is Correct i think so

My Function in C# for generating Json String.
public JsonResult barc()
{

var ab = 0;
var ba = 0;
StringBuilder resul = new StringBuilder();
var query = from o in db.report_mst
group o by o.test_id
into g
select new
{
Employee = g.Key,
Amount = g.Count()
};
resul.Append("[");

foreach (var q in query)
{ ab = q.Employee;
ba = q.Amount;
resul.Append("{ \"y\": \"" + ab + "\", \"a\": \"" + ba + "\" },");

}
resul.Remove(resul.Length - 1, 1);
resul.Append("]");

return Json(resul.ToString(), JsonRequestBehavior.AllowGet);
}


My Javascript..
<script type="text/javascript">
var anc;
$.ajax({
url: '/Report/barc/',
type: "POST",
dataType: "json",
success: function (resul) {

anc = JSON.stringify(resul);

alert(resul);


}


});
Morris.Bar({
element: 'bar-example',
data: anc,
// data: [ { a : 100,
// y : 2006
// },
//{ "a" : 75,
// "y" : 2007
//},
//{ "a" : 50,
// "y" : 2008
//},
//{ "a" : 75,
// "y" : 2009
//},
//{ "a" : 50,
// "y" : 2010
//},
//{ "a" : 75,
// "y" : 2011
//},
//{ "a" : 100,
// "y" : 2012
//}
// ],
xkey: 'y',
ykeys: ['a'],
labels: ['No of times']
});
</script>

Please help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900