gpt4 book ai didi

php - Symfony2 - Highcharts 渲染一个空白的 div

转载 作者:可可西里 更新时间:2023-10-31 23:39:22 24 4
gpt4 key购买 nike

我刚刚在 Symfony 2.7 上安装了 Highcharts Bundle,但在尝试从文档(cf https://github.com/marcaube/ObHighchartsBundle/blob/master/Resources/doc/usage.md)中重现“使用示例”时我已经遇到了问题

这是我的代码:

Controller

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 文件之前导入的,所以我真的不知道看看问题出在哪里... :(

如果有任何帮助,我将不胜感激! :)

干杯,

最佳答案

您指的是错误的 html ID

    $ob->chart->renderTo('piechart'); //This is looking for html element with id as piechart
<div id="linechart" style="min-width: 400px; height: 400px; margin: 0 auto"> </div>

改成

    $ob->chart->renderTo('linechart');

关于php - Symfony2 - Highcharts 渲染一个空白的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31159807/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com