Rank: Newbie
Groups: Registered
Joined: 4/23/2015(UTC) Posts: 2
Thanks: 0 times Was thanked: 0 time(s) in 0 post(s)
|
Hi, I would like to know if it is possible to do all chart initialization stuff inside a WebMethod in C#. This is what am trying to do: #Default.aspx.cs Code: [WebMethod()] public static string GetData() {
ArrayList jqChart = new ArrayList();
ArrayList dat = new ArrayList();
int[] first = {1, 15, 8}; int[] second = {2, 18, 14}; int[] third = {4, 15, 8};
dat.Add(first); dat.Add(second); dat.Add(third);
jqChart.Add(new { title = "Bubble Chart", shadows = new { enabled = true },
border = new { strokeStyle = "#6ba851" },
series = new { type = "bubble", title = "Series 1", fillStyle = "#418CF0", data = dat, markers = new { lineWidth = 1, strokeStyle = "black" } } });
string ans = JsonConvert.SerializeObject(jqChart, Formatting.Indented);
return ans; }
Now my JSON object looks like this: [ { "title": "Bubble Chart", "shadows": { "enabled": true }, "border": { "strokeStyle": "#6ba851" }, "series": { "type": "bubble", "title": "Series 1", "fillStyle": "#418CF0", "data": [ [ 1, 15, 8 ], [ 2, 18, 14 ], [ 4, 15, 8 ] ], "markers": { "lineWidth": 1, "strokeStyle": "black" } } } ] My Default.aspx is: Code: $(document).ready(function () {
$.ajax({ type: "POST", async: false, url: "Default.aspx/GetData", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { var o = JSON.parse(msg.d); $('#jqChart').jqChart(o[0]); // Can I directly pass my json response object to jqChart like this?? },
error: function (msg) { alert("Error"); } }); });
Sorry if it is a dumb question, but am trying to implement this idea. Looking forward to some help. Correct me if there are any mistakes in my code snippets. Thanks, Sheshu
|