Here is the var_dump for my query in my code:
array (size=2)
0 =>
array (size=4)
0 =>
array (size=1)
'barbell_curl_1_weight' => int 15
1 =>
array (size=1)
'barbell_curl_1_weight' => int 20
2 =>
array (size=1)
'barbell_curl_1_weight' => int 25
3 =>
array (size=1)
'barbell_curl_1_weight' => int 20
Here's my query:
/**
* @param User $user
* @param String $col
* @return array
*/
public function getStatsForStatsByDQL(User $user, String $col)
{
$parameters = (array('user' => $user,
));
$em2 = $this->getDoctrine()->getManager()
->getRepository('AppBundle:ExerciseStats')
->createQueryBuilder('g')
->setParameters($parameters)
->where('g.user = :user')
->select('g.'. $col)
->setMaxResults(12)
->join('g.user', 'user')
->orderBy( 'g.'. 'timestamp','ASC')
->getQuery()->getResult(Query::HYDRATE_ARRAY);
return $em2;
}
As you see from the var_dump, I'm getting the data I need back. Here's the Highcharts function it goes in:
/**
* @return \Symfony\Component\HttpFoundation\Response
* @Route ("user/stats", name="user_stats")
*/
public function chartAction()
{
$user = $this->getUser();
// Chart
$query = $this->getStatsForStatsByDQL($user,
ExerciseConsts::BARBELL_CURL_1_WEIGHT);
$series = array($query, array("name" => "weight", "data" =>
$query));
$ob = new Highchart();
$ob->chart->renderTo('linechart');
$ob->title->text('Barbell Curl Weight');
$ob->xAxis->title(array('text' => "Workouts"));
$ob->yAxis->title(array('text' => "Weight"));
$ob->series($series);
return $this->render('user/stats.html.twig', array(
'chart' => $ob
));
}
So all I'm getting back is 0. When using breakpoints in xdebug, I get back this:
1 = {array} [2]
name = "weight"
data = {array} [4]
0 = {array} [1]
barbell_curl_1_weight = 15
1 = {array} [1]
barbell_curl_1_weight = 20
2 = {array} [1]
barbell_curl_1_weight = 25
3 = {array} [1]
barbell_curl_1_weight = 20
How do I extract the weights and get it into the Highchart graph? Documentation for the Highcharts Bundle is completely lacking in this regard. Let me know if anyone has any clues. Thanks!
Here's the var_dump of json_encode($series, JSON_NUMERIC_CHECK). Maybe this will help:
string '[[{"barbell_curl_1_weight":15},{"barbell_curl_1_weight":20},{"barbell_curl_1_weight":25},{"barbell_curl_1_weight":20}],{"name":"weight","data":[{"barbell_curl_1_weight":15},{"barbell_curl_1_weight":20},{"barbell_curl_1_weight":25},{"barbell_curl_1_weight":20}]}]' (length=266)
I found the solution. As we are dealing with a multi-dimensional array, Highcharts is not drilling down beyond the first array, which returns 0. Here's my iteration to return the values of each array:
$temp = array();
foreach($array as $k=>$v){
if(is_array($v)){
foreach($v as $key=>$value){
$temp[] = $value;
}
}
}
So now, I just need to replace $temp with $query and voila', the chart is rendered with all values correctly.