Symfony2中Highcharts的JSON数据与ObHighchartsBundle

Symfony2中Highcharts的JSON数据与ObHighchartsBundle,json,symfony,highcharts,Json,Symfony,Highcharts,我使用ObHighchartsBundle来支持Symfony2中的Highcharts。只要我有一个定义好的php数组和数据,一切都很好 但我想使用json数据,例如在文件中——我如何实现这一点 提前谢谢 控制器类: HTML小枝: 我们已经找到了解决方案: HTML.Twig: 控制器: public function chartAction() { $series = array( array( "name"

我使用ObHighchartsBundle来支持Symfony2中的Highcharts。只要我有一个定义好的php数组和数据,一切都很好

但我想使用json数据,例如在文件中——我如何实现这一点

提前谢谢

控制器类:

HTML小枝:


我们已经找到了解决方案:

HTML.Twig:

控制器:

public function chartAction()
{
            $series = array(
            array(
                "name" => "Input",
                "data" => $this->getArray()
            ),
            array(
                "name" => "Output",
                "data" => $this->getArray())
        );

        $ob->chart->renderTo('datachart');  // The #id of the div where to render the chart
        $ob->chart->backgroundColor('transparent');
        $ob->title->text("Hello Title");

        $ob->xAxis->type('datetime');
        $ob->chart->zoomType("x");

        $ob->xAxis->title(array('text' => "Horizontal axis title"));
        $ob->yAxis->title(array('text' => "Vertical axis title"));
        $ob->series($series);

        return $this->render(':charts:charts.html.twig', array(
            'chart' => $ob
        ));
}
{% block head %}
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>

    <script src="//code.highcharts.com/4.1.8/highcharts.js"></script>
    <script src="//code.highcharts.com/4.1.8/modules/exporting.js"></script>
    <script type="text/javascript">
        {{ chart(chart) }}
    </script>

{% endblock %}

{% block body %}

<div id="datachart" style="min-width: 400px; height: 400px; margin: 0 auto;"></div>

{% endblock %}
script type="text/javascript">
            $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-v.json&callback=?', function (data) {
            {{ chart(chart, false) }}
    });
$ob->series(array(
            array('data' => new \Zend\Json\Expr('data'))
        ));