I have a View using a Chart format and it works fine using Views 3.0-rc3 when it is displaying only a single node's worth of data. However, I'm trying to sum up totals from several nodes' worth of fields. So I do this by setting Use Aggregation: Yes, then going to each field and setting the aggregation for that field to SUM.

Well, under Views 3.0-rc3 and Chart 7x-1.1, the SUM doesn't work. This is apparently a known issue as reported here. The recommendation in that thread is to update to Views 3.x-dev. Doing so disables the Chart format -- I tried all the choices (Pie, Horizontal Bar, etc) and it never shows.

SUM aggregation works just fine when displayed as a table, so Views is correctly rendering the data. But Charts has an issue.

I've also updated the Chart module to 7.x-1.x-dev. No difference there either.

CommentFileSizeAuthor
#8 chart-1357454-8.patch1.6 KBzhuber
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pbeakley’s picture

Priority: Normal » Major

A couple things: bumping this to major -- it's major to me! -- and providing some examples.

First off, I backed this back down to Views7.x-3.0-rc3 (because this apparently is the version where aggregation is fixed). Still using Chart7.x-1.x-dev.

Here's the table version, showing that aggregation is working just fine. The items shown are aggregated from three different nodes, each with a variety of entries. I checked the math and it's fine. Link to the page.

And here's the crazy Chart, showing all the various entries but showing that none of them have been aggregated at all. Link to the chart.

Finally, here's the SQL query generated by Views:

SELECT field_data_field_project.field_project_nid AS field_data_field_project_field_project_nid, node.created AS node_created, MIN(node.nid) AS nid, 'node' AS field_data_field_project_node_entity_type, 'node' AS field_data_field_tonnage_asphalt_node_entity_type, SUM(field_data_field_tonnage_asphalt.field_tonnage_asphalt_value) AS field_data_field_tonnage_asphalt_field_tonnage_asphalt_value, 'node' AS field_data_field_tonnage_cardboard_node_entity_type, SUM(field_data_field_tonnage_cardboard.field_tonnage_cardboard_value) AS field_data_field_tonnage_cardboard_field_tonnage_cardboard_v, 'node' AS field_data_field_tonnage_concrete_node_entity_type, SUM(field_data_field_tonnage_concrete.field_tonnage_concrete_value) AS field_data_field_tonnage_concrete_field_tonnage_concrete_val, 'node' AS field_data_field_tonnage_nonrecyclable_node_entity_type, SUM(field_data_field_tonnage_nonrecyclable.field_tonnage_nonrecyclable_value) AS field_data_field_tonnage_nonrecyclable_field_tonnage_nonrecy, 'node' AS field_data_field_tonnage_green_node_entity_type, SUM(field_data_field_tonnage_green.field_tonnage_green_value) AS field_data_field_tonnage_green_field_tonnage_green_value, 'node' AS field_data_field_tonnage_drywall_node_entity_type, SUM(field_data_field_tonnage_drywall.field_tonnage_drywall_value) AS field_data_field_tonnage_drywall_field_tonnage_drywall_value, 'node' AS field_data_field_tonnage_metals_iron_node_entity_type, SUM(field_data_field_tonnage_metals_iron.field_tonnage_metals_iron_value) AS field_data_field_tonnage_metals_iron_field_tonnage_metals_ir, 'node' AS field_data_field_tonnage_misc_node_entity_type, SUM(field_data_field_tonnage_misc.field_tonnage_misc_value) AS field_data_field_tonnage_misc_field_tonnage_misc_value, 'node' AS field_data_field_tonnage_inert_mixed_node_entity_type, SUM(field_data_field_tonnage_inert_mixed.field_tonnage_inert_mixed_value) AS field_data_field_tonnage_inert_mixed_field_tonnage_inert_mix, 'node' AS field_data_field_tonnage_metals_mixed_node_entity_type, SUM(field_data_field_tonnage_metals_mixed.field_tonnage_metals_mixed_value) AS field_data_field_tonnage_metals_mixed_field_tonnage_metals_m, 'node' AS field_data_field_tonnage_wood_mixed_node_entity_type, SUM(field_data_field_tonnage_wood_mixed.field_tonnage_wood_mixed_value) AS field_data_field_tonnage_wood_mixed_field_tonnage_wood_mixed, 'node' AS field_data_field_tonnage_wood_node_entity_type, SUM(field_data_field_tonnage_wood.field_tonnage_wood_value) AS field_data_field_tonnage_wood_field_tonnage_wood_value
FROM 
{node} node
LEFT JOIN {field_data_field_project} field_data_field_project ON node.nid = field_data_field_project.entity_id AND (field_data_field_project.entity_type = 'node' AND field_data_field_project.deleted = '0')
LEFT JOIN {field_data_field_tonnage_asphalt} field_data_field_tonnage_asphalt ON node.nid = field_data_field_tonnage_asphalt.entity_id AND (field_data_field_tonnage_asphalt.entity_type = 'node' AND field_data_field_tonnage_asphalt.deleted = '0')
LEFT JOIN {field_data_field_tonnage_cardboard} field_data_field_tonnage_cardboard ON node.nid = field_data_field_tonnage_cardboard.entity_id AND (field_data_field_tonnage_cardboard.entity_type = 'node' AND field_data_field_tonnage_cardboard.deleted = '0')
LEFT JOIN {field_data_field_tonnage_concrete} field_data_field_tonnage_concrete ON node.nid = field_data_field_tonnage_concrete.entity_id AND (field_data_field_tonnage_concrete.entity_type = 'node' AND field_data_field_tonnage_concrete.deleted = '0')
LEFT JOIN {field_data_field_tonnage_nonrecyclable} field_data_field_tonnage_nonrecyclable ON node.nid = field_data_field_tonnage_nonrecyclable.entity_id AND (field_data_field_tonnage_nonrecyclable.entity_type = 'node' AND field_data_field_tonnage_nonrecyclable.deleted = '0')
LEFT JOIN {field_data_field_tonnage_green} field_data_field_tonnage_green ON node.nid = field_data_field_tonnage_green.entity_id AND (field_data_field_tonnage_green.entity_type = 'node' AND field_data_field_tonnage_green.deleted = '0')
LEFT JOIN {field_data_field_tonnage_drywall} field_data_field_tonnage_drywall ON node.nid = field_data_field_tonnage_drywall.entity_id AND (field_data_field_tonnage_drywall.entity_type = 'node' AND field_data_field_tonnage_drywall.deleted = '0')
LEFT JOIN {field_data_field_tonnage_metals_iron} field_data_field_tonnage_metals_iron ON node.nid = field_data_field_tonnage_metals_iron.entity_id AND (field_data_field_tonnage_metals_iron.entity_type = 'node' AND field_data_field_tonnage_metals_iron.deleted = '0')
LEFT JOIN {field_data_field_tonnage_misc} field_data_field_tonnage_misc ON node.nid = field_data_field_tonnage_misc.entity_id AND (field_data_field_tonnage_misc.entity_type = 'node' AND field_data_field_tonnage_misc.deleted = '0')
LEFT JOIN {field_data_field_tonnage_inert_mixed} field_data_field_tonnage_inert_mixed ON node.nid = field_data_field_tonnage_inert_mixed.entity_id AND (field_data_field_tonnage_inert_mixed.entity_type = 'node' AND field_data_field_tonnage_inert_mixed.deleted = '0')
LEFT JOIN {field_data_field_tonnage_metals_mixed} field_data_field_tonnage_metals_mixed ON node.nid = field_data_field_tonnage_metals_mixed.entity_id AND (field_data_field_tonnage_metals_mixed.entity_type = 'node' AND field_data_field_tonnage_metals_mixed.deleted = '0')
LEFT JOIN {field_data_field_tonnage_wood_mixed} field_data_field_tonnage_wood_mixed ON node.nid = field_data_field_tonnage_wood_mixed.entity_id AND (field_data_field_tonnage_wood_mixed.entity_type = 'node' AND field_data_field_tonnage_wood_mixed.deleted = '0')
LEFT JOIN {field_data_field_tonnage_wood} field_data_field_tonnage_wood ON node.nid = field_data_field_tonnage_wood.entity_id AND (field_data_field_tonnage_wood.entity_type = 'node' AND field_data_field_tonnage_wood.deleted = '0')
WHERE (( (node.status = '1') AND (node.type IN  ('waste_report')) ))
GROUP BY field_data_field_project_field_project_nid, node_created
ORDER BY node_created DESC
pbeakley’s picture

Title: Views aggregation fix breaks the chart » Views aggregation breaks the chart

One last thing: removed the word "fix" from the title -- it's aggregation itself that breaks the Chart.

Pol’s picture

I also have the same problem.

sascher’s picture

subscribing

Pol’s picture


Please, stop writing such comments and use the top right button 'subscribe'...

13rac1’s picture

Priority: Major » Normal
Status: Active » Postponed (maintainer needs more info)

This is not Major. See: http://drupal.org/node/45111

Can someone describe how to reproduce this problem? Please write a simple step by step using a fresh Drupal install.

Note: A relevant error message is:

Warning: Illegal offset type in views_plugin_style->render_grouping() (line 311 of /sites/all/modules/views/plugins/views_plugin_style.inc).
13rac1’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

No response after five weeks. Please re-open if more information is available.

zhuber’s picture

Priority: Normal » Major
Status: Closed (cannot reproduce) » Needs review
FileSize
1.6 KB

This was definitely an issue, I just updated to the dev version and everything broke. Using aggregation now causes a white screen, which does not allow you to see the errors that are output to drupal.

According to the link you posted from d.o, this is a textbook 'Major' issue:

An example would be a PHP error which is only triggered under rare circumstances or which affects only a small percentage of all users

Here is the error message, for those of you who do not know how to use apache error logging:
PHP Fatal error: Unsupported operand types in /var/www/travel/sites/all/modules/contrib/chart/chart.module on line 489

The issue is that aggregration causes an issue with the _chart_get_max function, which is not expecting the possibility of empty items being in the array. I've patched this with a fix, and also cleaned up a few minor typos in the same function around line 489.

Here are some steps to replicate this issue:

  1. Create a view with a format of type 'Chart'
  2. Turn on aggregation by clicking 'Use Aggregation'
  3. Add these two fields and set the aggregation as follows:
    1. Title (Group results together)
    2. NID (COUNT)
  4. Remove the default sort criteria
  5. Save your view and try to display your new chart block somewhere on the site
  6. Cry
  7. Apply this patch
zhuber’s picture

Can we get this patch tested?

Pierre.Vriens’s picture

Issue summary: View changes
Parent issue: » #2371075: Chart 7.x-2.x Release

+1 for #6 and #7, though one might argue about the actual priority (depends who you ask?)

+2 for #8, THAT's how community works! Thanks Zak!

+3 for #9, anybody out there in those +25K sites still using chart who is willing to contribute a (motivated) status update about this issue, ideally "tested by community"?

Note the parent link I now added to push this issue forward somehow. The impact of that link might be that some day this issue becomes a release blocker (which is my current perception of this issue) ...

@pbeakley: consider editing #1 and transform (move) the SQL to an attached txt file which same content ... also: the chart I now see via that "link to chart" seems not that crazy (anymore). Actually it seems to match the table version also now. Maybe you can provide a status update on what happened in between, or what your fix was to resolve it?

To finish, it appears to me that this issue should now have a status like "Needs Review", but also "maintainer needs more info" (related to my questions about #1) . I'll wait for updates regarding the needs review (fingers crossed ...). If that doesn't help, I might want to change the status to "maintainer needs more info".

Pierre.Vriens’s picture

Unless this issue becomes "tested by community" ASAP, it won't make it into the 7.x-1.2 Release (to not put that release at risk). If it still gets tested "on time", it should be included I think. But "on time" now means "in the coming hours/days" ...