1

Hi I am setting some variables for highcharts in a Zend Report controller script like so:

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

etc.

the json I want to end up with also has this in:

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
            ]
        }
    }
}

So I need to setup the PHP array like so:

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

and so on. But I'm not sure how to do it because of the javascript function. The Zend report controller copies all the variables to the view script and I have no idea how it converts the php to json, but it does and it works :/ Sorry I can't be more helpful.

All I want is the outputted json to contain the javascript above, thanks!

2 Answers 2

1

Here's a solution that may help you: http://solutoire.com/2008/06/12/sending-javascript-functions-over-json/

Effectively the idea is to encode the function as a string and then decode it once it has been passed to javascript and before passing it into highcharts.

Sign up to request clarification or add additional context in comments.

Comments

0

It seems it is possible to encode javascript call backs in to json data with Zend. More information here: http://framework.zend.com/manual/en/zend.json.advanced.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.