Reputation: 11
Hi I'm trying to create a simple bar chart from a database query which outputs to a List
The C# is a simple list that pulls through "OSName" and "OS Count" and then converts to JSON Data.
List<string> googleDataset = new List<string>();
foreach(DataRow row in dsAssets.Rows)
{
googleDataset.Add("['" + row["OSNAME"] + "', " + row["OS Count"] + "]");
}
var jsonData = JsonConvert.SerializeObject(googleDataset);
I just cant find the correct Javascrript code to display this data in a Google Chart, the data that is created in the GoogleDataset List looks like :
['Win 2008 R2', 51]['Win 2016', 10]['Win 10', 4]['Win 2008', 4]['Win 7', 53]['Win 2012 R2', 22]['Win 10', 38]['Win 8.1', 1]['Win 10', 30]['Win 10', 8]['Win 10', 2]['Win 2008 R2', 2]['Win 2016', 3]['Win 7', 3]['Win 2012 R2', 1]['Win 10', 1]['Win 7', 2]['Win 2008 R2', 1]
Does anyone have an example of how I would accomplish this please ?
Cheers
Andy
Upvotes: 0
Views: 265
Reputation: 11
GoogleData = "<%=GoogleChartData%>";
GoogleData = GoogleData .trim();
GoogleData = GoogleData .replace(/'/g, '"');
GoogleData = jQuery.parseJSON(GoogleData);
var data = google.visualization.arrayToDataTable(GoogleData);
Upvotes: 1