Pass an array to jquery function to build chart

  I have a  Dictionary<string, int>  variable  users , which gets the data a total order count  in this format


Am building a chart from this data , so i need to transfer the data  to a jquery function  in this 2 kinds of  format

First format

second format - for x axis

Could you please help me how can i get those  formats ?.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Najam UddinCommented:
var a=  string.Join(",", dict.Select(d => string.Format("['{0}',{1}]", d.Key, d.Value)));

similarly you can create second one

var a=  string.Join(",", dict.Select(d => string.Format("'{0}{1}'", d.Key, d.Value)));

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zephyr_hex (Megan)DeveloperCommented:
JQuery interacts with the DOM, not with your server side code.  So, you'll need to use something like AJAX to get your Dictionary.  In order to do that, you need to convert your Dictionary to JSON .

Once you have your JSON string in Jquery, you can use $.parseJSON() to convert it into an array.  That's the first format you're requesting.  The second format is a string by using .toString() on the array.

Here's a general idea of the Ajax code:

                        type: "GET",
                        url: "yourcodefile.aspx/methodName",
                        dataType: "json",
                        success: function(response) {
                          //verify format you're receiving
                            var responseArray = $.parseJSON(response);
                            var responseString = responseArray.toString();

Open in new window

You method would look something like:

public static string methodName()


    return JsonConvert.SerializeObject( myDictionary );

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.