0
votes

I have problems while I insert data series on this function

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
    ));
}

Repository:

 public function findCantfar()
{

    $em = $this->getEntityManager();

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

    ');

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

thereby it's the result

$(function () { var piechart = new Highcharts.Chart({ chart: {"renderTo":"piechart"}, series: [{"name":"Serie Name","data":"Atamel","0":"115","type":"pie"}], title: {"text":"Chart Title"} }); });

Obviously, Data values are incorrect

How would pass correctly this data ?

regards

1

1 Answers

1
votes

The way that the foreach loop works, $datos will only hold the value of the last iteration AND the original value won't be changed.

Initialize your $series array before the loop and add another entry to that each iteration.