Welcome Guest Search | Active Topics |

Loading jqChart using WebMethod in C# through AJAX Call
Sheshu
#1 Posted : Monday, May 4, 2015 1:05:07 AM(UTC)
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
Dragan
#2 Posted : Monday, May 4, 2015 6:46:39 AM(UTC)
Rank: Advanced Member

Groups: Administrators, DataVizJavaScript, jQueryChart, jQueryDV, MvcChart, Registered
Joined: 1/3/2011(UTC)
Posts: 483

Thanks: 0 times
Was thanked: 87 time(s) in 87 post(s)
The code looks correct. Do you have any issues with it?
Best Regards,
Dragan Matek
jqChart Inc.
Sheshu
#3 Posted : Monday, May 4, 2015 8:16:33 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 4/23/2015(UTC)
Posts: 2

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
No issues. Working now!!

Thanks,
Sheshu
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

FlatEarth Theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.134 seconds.