嗨,我在 Zend Report 控制器脚本中为 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报告控制器将所有变量复制到视图脚本中,我不知道它如何将php转换为json,但它确实如此并且有效:/对不起,我不能提供更多帮助。
我想要的只是输出的json包含上面的javascript,谢谢!
这里有一个可能对你有帮助的解决方案: http://solutoire.com/2008/06/12/sending-javascript-functions-over-json/
实际上,这个想法是将函数编码为字符串,然后在它传递给javascript之后对其进行解码,然后再将其传递给highcharts。
似乎可以使用Zend将javascript回调编码为json数据。更多信息请点击此处:http://framework.zend.com/manual/en/zend.json.advanced.html