1

I am getting Year and 'NoOfOrders' from a Web Method through ajax call. I want to convert Json object to array so that I can plot using jqbargraph.

$(document).ready(function () {
    var myArray = [];
    $("[id$=btnSubmit]").click(function () {
        $.ajax({
            type: "POST",
            url: "Charts.aspx/GetOrderCount",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                var OrdersInfo = data.d;
                $.each(OrdersInfo, function (index, order) {
                    myArray.push(order.OrderYear, order.OrderCount);
                });
            }
        });
        $('#divChart').jqbargraph({
            data: myArray,
            position: 'bottom',
            animate: false
        });
    });
});
1
  • So what's the problem? What isn't working and what error messages are you seeing? Commented Jul 17, 2012 at 19:57

1 Answer 1

2

Try to push an Array, instead of separate values into myArray:

$.each(OrdersInfo, function (index, order) {
      myArray.push([order.OrderYear, order.OrderCount]);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.