jqplot 不计算字符串


jqplot not evaluating string

我正在使用jqplot,并使用以下PHP代码构造了一个数组

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);
}

此代码输出我需要插入到 jqplot 函数中的正确代码。 下面是上面代码生成的数组:

[["2011-12-24",0],["2011-12-19",14],["2011-12-08",22],["2011-12-04",14],["2011-11-27",12]]

所以目前我正在将这个数组打印到屏幕上,然后使用 jQuery .text() 捕获字符串并将其放在变量中。 我可以回显出我分配数组字符串的 var 并且它工作正常,但是当我将其传递给 jqplot 函数时,它什么也不做。

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
          }
      });

为了使它更加复杂,如果我复制 PHP 生成的字符串并将其硬编码为 JS 中的变量,它可以工作。任何想法为什么 jqplot 插件不会评估我从使用 $(this).text(); 中获得的字符串.

这是我正在建模的jQplot示例: http://www.jqplot.com/tests/cursor-highlighter.php

使用这种方法帮助我解决了这个问题。我没有使用 jQuery 来访问打印的变量,而是在 PHP 页面的底部插入了一点 javascript 来捕获 PHP 中的局部变量,然后使用它传递到 jQplot 函数中。

将 PHP 字符串传递给 JavaScript 变量(并转义换行符)

直接使用 [p1array] 不带大括号并尝试...它应该像 p1array 一样工作