Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-15-2013, 03:33 AM   PM User | #1
Inaer
New to the CF scene

 
Join Date: Mar 2013
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Inaer is an unknown quantity at this point
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!
Inaer is offline   Reply With Quote
Old 03-15-2013, 08:21 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
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);
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
Inaer (03-18-2013)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:45 AM.


Advertisement
Log in to turn off these ads.