1

こんにちは、Zend Report コントローラー スクリプトでハイチャートの変数を次のように設定しています。

    $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を含めることだけです。ありがとう!

4

2 に答える 2

1

これがあなたを助けるかもしれない解決策です:http://solutoire.com/2008/06/12/sending-javascript-functions-over-json/

効果的には、関数を文字列としてエンコードし、javascript に渡された後、ハイチャートに渡す前にデコードするという考え方です。

于 2012-05-30T19:42:54.577 に答える
0

Zend を使用して、javascript コールバックを json データにエンコードすることは可能であるようです。詳細はこちら: http://framework.zend.com/manual/en/zend.json.advanced.html

于 2012-05-30T23:25:56.143 に答える