加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Symfony2 – Highcharts呈现空白div

发布时间:2020-12-13 15:56:55 所属栏目:PHP教程 来源:网络整理
导读:我刚刚在Symfony 2.7上安装了Highcharts Bundle,但我在尝试从文档中重现“使用示例”时遇到了一个问题(参见 https://github.com/marcaube/ObHighchartsBundle/blob/master/Resources/doc/usage.md) 这是我的代码: 调节器 public function homepageAction()
我刚刚在Symfony 2.7上安装了Highcharts Bundle,但我在尝试从文档中重现“使用示例”时遇到了一个问题(参见 https://github.com/marcaube/ObHighchartsBundle/blob/master/Resources/doc/usage.md)

这是我的代码:

调节器

public function homepageAction() 
{
    $user = $this->getUser();

    $securityContext = $this->get('security.context');
    $authorization = $securityContext->isGranted('ROLE_REGISTERED_USER');

    if ($authorization) {

        // Charts Test

        $ob = new Highchart();
        $ob->chart->renderTo('piechart');
        $ob->title->text('Browser market shares at a specific website in 2010');
        $ob->plotOptions->pie(array(
            'allowPointSelect' => true,'cursor' => 'pointer','dataLabels' => array('enabled' => false),'showInLegend' => true
        ));
        $data = array(
            array('Firefox',45.0),array('IE',26.8),array('Chrome',12.8),array('Safari',8.5),array('Opera',6.2),array('Others',0.7),);
        $ob->series(array(array('type' => 'pie','name' => 'Browser share','data' => $data)));

        return $this->render('MVPBundle:User:homepage.html.twig',array(
            'user' => $user,'chart' => $ob,));

    } else {

        $url = $this->generateUrl('user_displayCompanyCreationForm');

        return $this->redirect($url);
    }
}

视图

<script src='{{ asset('bundles/mvp/js/jquery-2.1.4.js') }}' type="text/javascript"></script>
<script src='{{ asset('bundles/mvp/js/highcharts.js') }}' type="text/javascript"></script>
<script src='{{ asset('bundles/mvp/js/exporting.js') }}' type="text/javascript"></script>

<script type="text/javascript">
    {{ chart(chart) }}
</script>

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

经过一些研究,我明白它可以与JS文件的导入相关联,所以我确保文件的路径是可以的,并且Jquery是在Highcharts JS文件之前导入的,所以我真的看不到问题来自……

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读