help with charts module

lasac - August 25, 2009 - 08:38

Ok i am trying to work this out for quite some time now, but im stuck.

In the blog users can select a activity and rate it, this is done with cck and multigroup to let them add more values then one. The snippet i am posting gets the data in the correct way. I just cant figure out how to place it in the charts snippet. One thing there is no hard amount of values so there could be only one value but there could also be ten.

<?php
$result
= db_query("SELECT
field_activiteit_value,
sum(asg.field_activiteit_stemming_value)
AS activiteit_total
FROM
content_field_activiteit AS a
LEFT JOIN
content_field_activiteit_stemming AS asg
ON
asg.vid = a.vid
AND
asg.nid = a.nid
AND
asg.delta = a.delta
LEFT JOIN
node AS n
ON
n.nid = a.nid
WHERE
field_activiteit_stemming_value IS NOT NULL
AND
field_activiteit_value IS NOT NULL
AND
uid = 84
AND
status = 1
GROUP BY
a.field_activiteit_value"
);

while(
$data = db_fetch_array($result)):

  foreach(
$data as $ding => $waarde):
 
       if(
is_numeric($waarde)):
        
$perc = $waarde / '26' * 100;
       endif;
      
  endforeach;
 
 
$chart[$data[field_activiteit_value]] = $perc;

endwhile;


print_r($chart);


/*$example = array(
  '#type'     => 'pie2D', // Display a 3D pie chart
  '#color'    => 'f0f0f0', // Background color, in RRGGBB format
  '#title'    => t('Activiteiten'), // Chart title
  array(
    array('#value' => 60, '#label' => ),
    array('#value' => 25, '#label' => $data->field_activiteit_value),
    array('#value' => 10, '#label' => $data->field_activiteit_value),
    array('#value' => 5,  '#label' => $data->field_activiteit_value),
  ),
);
return charts_chart($example);*/

?>

The result i get with print_r($chart);

Array ( [activity one] => 11.5384615385 [activity two] => 23.0769230769 [activity three] => 23.0769230769 [activity four] => 42.3076923077 )

So as you see i get the value and am able to convert it to a percentage of the total, i just can figure out how to place it in the charts snippet, really hope someon can help me out with this.

Got it working with:

<?php
$result
= db_query("SELECT
field_activiteit_value,
sum(asg.field_activiteit_stemming_value)
AS activiteit_total
FROM
content_field_activiteit AS a
LEFT JOIN
content_field_activiteit_stemming AS asg
ON
asg.vid = a.vid
AND
asg.nid = a.nid
AND
asg.delta = a.delta
LEFT JOIN
node AS n
ON
n.nid = a.nid
WHERE
field_activiteit_stemming_value IS NOT NULL
AND
field_activiteit_value IS NOT NULL
AND
uid = 84
AND
status = 1
GROUP BY
a.field_activiteit_value"
);


while(
$data = db_fetch_array($result)):
$datas[$data[field_activiteit_value]] = $data[activiteit_total];
endwhile;

$totaal = array_sum($datas);

foreach(
$datas as $ding => $waarde):
    
$perc = $waarde / $totaal * 100;
    
$chart[] = array('#value' => $perc, '#label' => $ding);
endforeach;


$example = array(
 
'#type'     => 'pie2D', // Display a 3D pie chart
 
'#color'    => 'f0f0f0', // Background color, in RRGGBB format
 
'#title'    => t('Activiteiten'), // Chart title
 
$chart,
);
return
charts_chart($example);

?>

I got it with $example =

lasac - August 25, 2009 - 09:51

got it, see above

 
 

Drupal is a registered trademark of Dries Buytaert.