I have the PIE chart with some values:

 $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

murz’s picture

Correct php code is

$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);
murz’s picture

If I change the line 447 in chart.module file from
$data[$k] = floor($v / $divider);
to
$data[$k] = ceil($v / $divider);
The pie looks normally:
http://chart.apis.google.com/chart?chd=t1%3A100%2C20%2C8%2C5%2C2%2C1%2C1...

murz’s picture

I have found the source of the problem!
In file chart.module function _chart_adjust_resolution() there are string:
if ($v != 'NULL' && $v > 0){
NULL must not be in quotes, the correct code is:
if ($v != NULL && $v > 0){
and another error in function _chart_encode_data($data)
if ($v != 'NULL'){
must be
if ($v != NULL){
but for normal show the zero values I recommend this variant:
if (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

haagendazs’s picture

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.

mindbat’s picture

StatusFileSize
new639 bytes

Thanks for posting a fix, Murz!

I've taken the liberty of rolling that fix into a patch.

13rac1’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new690 bytes

Same patch for current 7.x-1.x-dev.

13rac1’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Needs review » Patch (to be ported)

Patch applied to 7.x-1.x-dev. Needed in 6.x-1.x-dev.

13rac1’s picture

Status: Patch (to be ported) » Closed (duplicate)
Pierre.Vriens’s picture

Issue summary: View changes
Parent issue: » #2371567: Chart 6.x-2.x Release