饼图显示系列

时间:2017-07-11 13:08:46

标签: php highcharts

我想显示每个实验室的项目数量,实验室列表是一个集合

在我的情况下,系列列表是动态的

我的问题:派生成第一个项目LAB

enter image description here

ProjectLab实体:

class ProjectLab
{
 /**
 * 
 * @ORM\ManyToOne(targetEntity="Form", inversedBy="projectLab")
 * @ORM\JoinColumn(name="form_id", referencedColumnName="id")
 */
private $form;
}

表单实体:

class Form
{

/**
 *.
 * @ORM\OneToMany(targetEntity="ProjectLab", mappedBy="form", cascade={"all"})
 */
private $projectLab;
}

我的chartPie功能:

public function chartPie(Survey $survey)
{

    $center = $survey ->getCenter();
    $form = $survey->getForm();
    $ob = new Highchart();
    $ob->chart->renderTo('containerpie');
    $ob->chart->type('pie');
    $ob->chart->options3d(array('enabled' => true,'alpha'=> '45','beta'=> null));


    $ob->plotOptions->pie(array(
        'depth' => '25',
        'allowPointSelect'  => true,
        'cursor'    => 'pointer',
        'dataLabels'    => array('enabled' => true , 'format'=> '{point.name}'),
        'showInLegend'  => true
    ));

    $ob->title->text('List project per lab');

   $listLabProject =$form ->getProjLab();


    foreach($listLabProject as $lab) {

        $data = array(
            array($lab->getProjLab(),$lab->getNbProject()));
    }

    $ob->series(array(array('type' => 'pie','name' => 'Number', 'data' =>    $data)));
    return $ob;
}

1 个答案:

答案 0 :(得分:0)

foreach循环中,您每次都会覆盖$data而不是附加到$data = array(); foreach($listLabProject as $lab) { array_push($data,array($lab->getProjLab(),$lab->getNbProject())); } 。尝试这样的事情:

var poly = data.features[0].geometry.coordinates
console.log(poly)