Posted by Murz on October 28, 2009 at 6:11pm
| Project: | Google chart API |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (duplicate) |
Issue Summary
I have the PIE chart with some values:
<?php
$chart = array(
'#chart_id' => uniqid(),
'#type' => CHART_TYPE_PIE_3D,
'#size' => chart_size(500, 160),
'#adjust_resolution' => TRUE,
);
$chart['#data'] = array([0] => 529 [1] => 102 [2] => 41 [3] => 25 [4] => 10 [5] => 5 [6] => 1 [7] => 1 );
$chart['#data_colors'] = array('78c0e9', 'ffe500', '50b432', 'ed561b');
echo chart_render($chart);
?>If I turn on "#adjust_resolution = true" I see a PIE with only 2 normal zones, and all other becomes zero-sized! Example:
http://chart.apis.google.com/chart?chd=t1%3A99%2C19%2C7%2C4%2C1%2C-1%2C-...
If I don't use "#adjust_resolution = true" option, I see the chart with bad size of zones (first zone must be much than 5 times bigger that other). Example:
http://chart.apis.google.com/chart?chd=t1%3A529%2C102%2C41%2C25%2C10%2C5...
Why after adjusing resolution i didn't see other zones and some values becomes -1?
Comments
#1
Correct php code is
<?php$chart = array(
'#chart_id' => uniqid(),
'#type' => CHART_TYPE_PIE_3D,
'#size' => chart_size(500, 160),
'#adjust_resolution' => TRUE,
);
$chart['#data'] = array(529, 102, 41, 25, 10, 5, 1, 1);
$chart['#data_colors'] = array('78c0e9', 'ffe500', '50b432', 'ed561b');
echo chart_render($chart);
?>
#2
If I change the line 447 in chart.module file from
<?php$data[$k] = floor($v / $divider);
?>
to
<?php$data[$k] = ceil($v / $divider);
?>
The pie looks normally:
http://chart.apis.google.com/chart?chd=t1%3A100%2C20%2C8%2C5%2C2%2C1%2C1...
#3
I have found the source of the problem!
In file
chart.modulefunction_chart_adjust_resolution()there are string:<?phpif ($v != 'NULL' && $v > 0){
?>
NULL must not be in quotes, the correct code is:
<?phpif ($v != NULL && $v > 0){
?>
and another error in function
_chart_encode_data($data)<?phpif ($v != 'NULL'){
?>
must be
<?phpif ($v != NULL){
?>
but for normal show the zero values I recommend this variant:
<?phpif (is_numeric($v)){
?>
because in first variant the pie charts with zero values shows bad!
values: 8,0,100,13
chart with
if ($v != NULL):http://chart.apis.google.com/chart?chd=t1%3A8%2C-1%2C100%2C13&cht=p3&chs...
value string: 8,-1,100,13
chart with
if (is_numeric($v)):http://chart.apis.google.com/chart?chd=t1%3A8%2C0%2C100%2C13&cht=p3&chs=...
value string: 8,0,100,13
#4
Murz: I am using the 6.x-1.2 version of the Chart API module and had the same problem. Your fix described in #3 works great. Thanks a lot for figuring this out and sharing with us.
#5
Thanks for posting a fix, Murz!
I've taken the liberty of rolling that fix into a patch.
#6
Same patch for current 7.x-1.x-dev.
#7
Patch applied to 7.x-1.x-dev. Needed in 6.x-1.x-dev.
#8
Just realized, this is a dupe of #245532: formatting error for xy line charts, and issue with data that is equal to 0