Symfony2:Highchartsbundle数据问题

时间:2015-01-08 00:39:55

标签: javascript symfony highcharts

我在此功能上插入数据系列时遇到问题

public function chartAction()
{

    $em = $this->getDoctrine()->getManager();

    $entities = $em->getRepository('FarmacoBundle:Farmaco')->findCantfar();

    foreach($entities as $datos)
    {
        $datos['nombreComercial'];
        $datos['existencia'];

    }

    $series = array(

    array("name" => "Serie Name",  "data" => $datos['nombreComercial'], $datos['existencia'], "type" => "pie")
    );

    $ob = new Highchart();
    $ob->chart->renderTo('piechart');  
    $ob->title->text('Chart Title');
    $ob->series($series);

    return $this->render('FarmacoBundle:Default:chart.html.twig', array(
    'chart' => $ob
    ));
}

存储库:

 public function findCantfar()
{

    $em = $this->getEntityManager();

    $query = $em->createQuery('
    SELECT f.nombreComercial, f.existencia
        FROM FarmacoBundle:Farmaco f 

    ');

    $query->setMaxResults(4);
    return $query->getResult();
}

因此它是结果

   $(function(){var piechart = new   Highcharts.Chart({chart:{" renderTo":" piechart"},系列:   [{" name":" Serie Name"," data":" Atamel"," 0":&# 34; 115""类型":"馅饼"}],   标题:{"文字":"图表标题"}       }); });

显然,数据值不正确

如何正确传递这些数据?

问候

1 个答案:

答案 0 :(得分:1)

foreach循环的工作方式,$datos只保存最后一次迭代的值,原始值不会改变。

在循环之前初始化$series数组,并为每次迭代添加另一个条目。