I use AJAX to get my data from SQL Server, then I prepare a js array that is used as data in my diagram. JavaScript code after successful AJAX:
..., success: function (data) { var fseries = []; var series = []; for (var arr in data) { for (var i in data[arr]['data'] ){ var d = data[arr]['data'][i]; //if (i < 5) alert("d.method = " + d.method); var serie = {x:Date.parse(d.Value), y:d.Item, method:d.method }; series.push(serie); } fseries.push({name: data[arr]['name'], data: series, location: data[arr]['location']}); series = []; }; DrawChart(fseries); },
Now, to show additional metadata in the tooltip:
... tooltip: { xDateFormat: '%m/%d/%y', headerFormat: '<b>{series.name}</b><br>', pointFormat: 'Method: {point.method}<br>Date: {point.x:%m/%d/%y } <br>Reading: {point.y:,.2f}', shared: false, },
I use DataRow to iterate over my result set, and then I use the class to assign values ββbefore passing in Json format. Here is the C # code in the controller action called by Ajax.
public JsonResult ChartData(string dataSource, string locationType, string[] locations, string[] methods, string fromDate, string toDate, string[] lstParams) { List<Dictionary<string, object>> dataResult = new List<Dictionary<string, object>>(); Dictionary<string, object> aSeries = new Dictionary<string, object>(); string currParam = string.Empty; lstParams = (lstParams == null) ? new string[1] : lstParams; foreach (DataRow dr in GetChartData(dataSource, locationType, locations, methods, fromDate, toDate, lstParams).Rows) { if (currParam != dr[1].ToString()) { if (!String.IsNullOrEmpty(currParam))
I understand that in C # there is a more efficient and acceptable way to code, but I inherited the project.