发送PHP中的javascript函数,将其格式化为JSON(highcharts)

发送PHP中的javascript函数,将其格式化为JSON(highcharts),php,json,zend-framework,highcharts,Php,Json,Zend Framework,Highcharts,您好,我正在Zend Report controller脚本中为highcharts设置一些变量,如下所示: $chartOptions = array( "chart"=> array( //chart type "type" => "bar", "spacingBottom" => 25 ), "height"=>1,

您好,我正在Zend Report controller脚本中为highcharts设置一些变量,如下所示:

    $chartOptions = array(
        "chart"=> array(
            //chart type
            "type" => "bar",
                    "spacingBottom" => 25
        ),
        "height"=>1,
        "title" => array(
            "text" => $spm->getFullName()
        ),
等等

我希望最终使用的json还有以下内容:

exporting: {
    buttons: {
        exportButton: {
            menuItems: [{
                text: 'Export to PNG (with text)',
                onclick: function() {
                    this.exportChart({},{
                        labels: {
                            items:[{
                                html: "System: x.x.x, Date/Time: 30:05:2012 14:32:00",
                                style: {
                                    left: '50%',
                                    top: '250px'
                                }                                            
                            }]
                        }
                    });
                }
            }, {
                text: 'Export to PNG (default)',
                onclick: function() {
                    this.exportChart();
                }
            },
            null,
            null
            ]
        }
    }
}
所以我需要像这样设置PHP数组:

$chartOptions = array(
    "chart"=> array(
        //chart type
        "type" => "bar",
        "spacingBottom" => 25
     ),
    "height"=>1,
    "title" => array(
        "text" => $spm->getFullName()
    ),
    "exporting" => "buttons" =>
等等。但由于javascript函数的原因,我不确定如何实现它。Zend report controller将所有变量复制到视图脚本中,我不知道它是如何将php转换为json的,但它是这样做的,并且工作正常:/抱歉,我帮不上什么忙


我只希望输出的json包含上面的javascript,谢谢

这里有一个解决方案可以帮助您:


实际上,我们的想法是将函数编码为字符串,然后在将其传递到javascript之后,在将其传递到highcharts之前对其进行解码。

以下是一个可能对您有所帮助的解决方案:


实际上,我们的想法是将函数编码为字符串,然后在将其传递到javascript之后,在将其传递到highcharts之前对其进行解码。

似乎可以使用Zend将javascript回调编码到json数据中。这里有更多信息:

似乎可以使用Zend将javascript回调编码到json数据中。更多信息请点击此处: