携带一个PHP数组到JavaScript和Plot与ggplot

时间:2013-03-22 16:09:12

标签: php arrays jqplot

我正在使用jqplot并且我绘制了一个来自数组php的数据但是当我尝试从javascript绘图时不能正常工作

这是代码php:

$array= array();
$array[] = 34.890;
$array[] = 25.090;

现在代码吸收了:

 <script>
 $(function() {

    var array = new Array();

    <?php
        for( $i=0; $i<count($array); $i++){
           echo "\narray[$i] = '$array[$i]';"; 
         }
   ?>
   graficar(  array  );
 });
 </script>

graficar函数是:

function graficar( array )
{

    var plot2 = $.jqplot('lienzo',
        [
            array
        ],
        {
            seriesDefaults: {
                renderer: $.jqplot.BarRenderer,
                // Show point labels to the right ('e'ast) of each bar.
                // edgeTolerance of -15 allows labels flow outside the grid
                // up to 15 pixels.  If they flow out more than that, they
                // will be hidden.
                pointLabels: {show: true, location: 'e', edgeTolerance: -15},
                // Rotate the bar shadow as if bar is lit from top right.
                shadowAngle: 135,
                // Here's where we tell the chart it is oriented horizontally.
                rendererOptions: {
                    barDirection: 'horizontal',
                    barWidth:18
                }
            },
            axes: {
                yaxis: {
                    renderer: $.jqplot.CategoryAxisRenderer
                }
            }
        }
   );

 }

我得到的错误是:

TypeError: this[r]._ticks[0] is undefined
[Break On This Error]   

 ...{href:function(a){return a.getAttribute("href")},type:function(a){return a.getAt...

图表显示:

enter image description here

如何解决我的麻烦?

坦克。

1 个答案:

答案 0 :(得分:0)

你的&#34;数组&#34;中出现了问题,就像在我的代码中一样,

array = ["0","0","0","0"]

array = ["w","r","o","n","g"]

发生错误,然后我应该使用parseInt方法将字符串元素解析为第一个整数。如果

array = ["1","2","3","4"]

没有必要将字符串元素解析为数组中的intger,jqplot会为你做,但如果数组就像前两个一样,这里就会出现错误。