I have just installed the Highcharts Bundle on Symfony 2.7, but I am already facing an issue while trying to reproduce the "Usage Example" from the documentation (cf http://ift.tt/1IPuHeC)
Here is my code :
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);
}
}
View
<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="linechart" style="min-width: 400px; height: 400px; margin: 0 auto"> </div>
After some research, I understood that it could be linked with the import of the JS files, so I made sure the paths to the files were okay, and that Jquery was imported before Highcharts JS files, so I really don't see where the problem comes from... :(
I would appreciate any help ! :)
Cheers,
Aucun commentaire:
Enregistrer un commentaire