I am using jqplot and have constructed an array with the following PHP code
if($fiveRes){
$lastNum = mysql_num_rows($fiveRes);
$testarray = array();
while($row = mysql_fetch_array($fiveRes, MYSQL_ASSOC)) {
$testarray[] = array($row['GameDate'], floatval($row['WKP']));
}
echo json_encode($testarray);
}
This code outputs the correct code that I need to insert into the jqplot function. Here is the array generated by the code above:
[["2011-12-24",0],["2011-12-19",14],["2011-12-08",22],["2011-12-04",14],["2011-11-27",12]]
So currently i'm printing this array to the screen, and then using jQuery .text() to capture the string and place it inside a variable. I can echo out the var that I assigned the array string to and it works correctly, however when I pass it into the jqplot function it does nothing.
var p1array = $('.col.first .parray').text();
alert(p1array); //Alerts the correct array formatted like above.
var plot1 = $.jqplot('jqplot0', [p1array], {
title:'Last 5 Fantasy Points',
axes:{
xaxis:{
renderer:$.jqplot.DateAxisRenderer,
tickOptions:{
formatString:'%b %#d'
}
},
yaxis:{
tickOptions:{
formatString:''
}
}
},
highlighter: {
show: true,
sizeAdjust: 7.5
},
cursor: {
show: false
}
});
To make it even more complicated, if I copy the string that the PHP generates and I hardcode it into a variable in JS it works. Any ideas why the jqplot plugin won't evaluate the string I get from using $(this).text();
.
Here is the jQplot example i'm modeling after: http://www.jqplot.com/tests/cursor-highlighter.php