我正在使用Highcharts的多轴图表。
它工作正常,但我不想显示我的变量,如果它是NULL,我应该把测试放在NULL值上?
我已经在饼图中完成了它,但是现在所有这些数组都丢失了
我的多轴图表函数,它采用由数年和4个数组组成的数组:
public function multiAxeChartDyn($date, $list1, $list2,$list3,$list4)
{
$dates = $date;
$ob = new Highchart();
$ob->chart->renderTo('containerMultiaxe'); // The #id of the div where to render the chart
$ob->chart->type('column');
$ob->title->text('Budget');
$ob->xAxis->categories($dates);
$ob->legend->enabled(true);
$dataSeries= array(
$list1,
$list2,
$list3,
$list4,
);
$yData = array(
array(
'labels' => array(
'formatter' => new Expr('function () { return this.value + " %" }'),
'style' => array('color' => '#AA4643')
),
'title' => array(
'text' => 'Taux',
'style' => array('color' => '#AA4643')
),
'opposite' => true,
),
array(
'labels' => array(
'formatter' => new Expr('function () { return this.value + " mDT" }'),
'style' => array('color' => '#4572A7')
),
'gridLineWidth' => 0,
'title' => array(
'text' => 'Budget',
'style' => array('color' => '#4572A7')
),
),
);
$ob->yAxis($yData);
$formatter = new Expr('function () {
var unit = {
"Budget": "mDT",
"Ressource": "mDT",
"Taux global": "%",
"Taux Consumption": "%"
}[this.series.name];
return this.x + ": <b>" + this.y + "</b> " + unit;
}');
$ob->tooltip->formatter($formatter);
$ob->series( $dataSeries);
return $ob;
}
我的控制员:
public function indexAction(Survey $survey)
{
$chart=new ChartController();
$ent = $survey ->getEnt();
$year= $survey->getYear();
$qb = $this->getDoctrine()->getManager()->createQueryBuilder();
$qb->select('e')
->from('AppBundle:Survey, 'e')
->where('e.year <= :year')
->andWhere('e.ent = :ent')
->setParameter('year', $year)
->setParameter('ent', $ent->getId())
->orderBy('e.year', 'DESC')
->setMaxResults(4);
$survey_year = $qb->getQuery()->getResult();
$date = array();
$data1 = array();
$data2 = array();
$data3 = array();
$data4 = array();
$survey_year= array_reverse($survey_year, true);
foreach($survey_year as $ea){
$date[] = $ea->getyear();
$data1[] = $ea->getForm ()->getBudget()/1000;
$data2[] = $ea->getForm ()->getRessources()/1000;
$data3[] = $ea->getForm ()->getTauxGlobal ();
$data4[] = $ea->getForm ()->getTauxConsumption ();
}
$list1= array(
'name' => 'Budget',
'type' => 'column',
'color' => '#4572A7',
'yAxis' => 1,
'dataLabels' => array(
'enabled' => true
),
'data' => $data1
);
$list2 = array(
'name' => 'Ressource',
'type' => 'column',
'color' => '#D49EDA',
'yAxis' => 1,
'dataLabels' => array(
'enabled' => true
),
'data' => $data2
);
$list3= array(
'name' => 'Taux global',
'type' => 'spline',
'color' => '#0A0F19',
'dataLabels' => array(
'enabled' => true
),
'data' => $data3
);
$list4 = array(
'name'=> 'Taux Consumption',
'type' => 'spline',
'color' => '#225824',
'dataLabels' => array(
'enabled' => true
),
'data' => $data4
);
$containermultiaxe=$chart->multiAxeChartDyn($date, $list1, $list2,$list3,$list4);
$html = $this->render('AppBundle:Charting:index.html.twig',array(
'survey' =>$survey,
'containerMultiaxe' => $containermultiaxe,
));
return $html;
}