Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Trouble with Google candlestick charts populated with jquery post.

    Like the title says, I am trying to use google's candlestick charts, specifically this one: https://code.google.com/apis/ajax/pl...dlestick_chart

    This is the part I'm having issues with:
    Code:
    var dataTable = google.visualization.arrayToDataTable([
           ['Mon', 20, 28, 38, 45],
           ['Tue', 31, 38, 55, 66],
           ['Wed', 50, 55, 77, 80],
           ['Thu', 77, 77, 66, 50],
           ['Fri', 68, 66, 22, 15]
        // Treat first row as data as well.
        ], true);
    Now to put my own data in there I'm trying to use jquery to post and return data from a php script and I'm quite sure this part works because I can append the data to a div. What I've got looks like this:

    Code:
    $.post("callback.php", { action: "2", sym: "SS.IN" })
    .done(function(data) {
            $.each($.parseJSON(data), function(index,value){
                    value.date
                    value.low
                    value.open
                    value.close
                    value.high
            });
    })
    I know that the above code doesn't output anything but I am just showing the available variables. The problem I'm having here is taking these values and adding them to google's code formatted correctly. At this point I am stumped and need help mixing the two.

    Thanks if you can help!

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    You need to push your values into an array and then push that array into another array. This second array will then be the parameter for the google visualisation.

    Code:
    var outerArray = [];
            $.each($.parseJSON(data), function(index,value){
                    var innerArray = [];
                    innerArray.push(value.date);
                    innerArray.push(value.low);
                    innerArray.push(value.open);
                    innerArray.push(value.close);
                    innerArray.push(value.high);
                    outerArray.push(innerArray);
            });
    var dataTable = google.visualization.arrayToDataTable(outerArray, true);

  • Users who have thanked devnull69 for this post:

    Inaer (03-18-2013)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •