I use the javascript graphics library that expects its data in a specific JSON format - without property names. I have an object in my model that I use to return data to charts. It looks like this:
public class ChartData
{
public string Key { get; set; }
public int Value { get; set; }
}
The action is as follows:
public ActionResult AssetsPerFloor(Guid id)
{
var results = from a in surveyRepository.GetAssetsForBuidling(id)
group a by a.Room.Floor into g
select new ChartData{ Key = g.Key.ToString(), Value = g.Count() };
return Json(results);
}
This returns JSON in the format [{"Key":"Main Building","Value":1}]
However, the diagram does not require property names, for example: [[5, 2], [6, 3], [8, 2]]
In any case, I can return the results in this format. I'm sure there is a simple trick, but I can't think about it.
source
share