In a pie chart, the first row of results is not included if the view field used for the data does not have a label set. I did not set a label initially because I did not want one to show on chart.

I figured out that the labels were the issue when I compared my view to the demo included with the module. Thanks for doing that!

What happened:

When I set the view format to Table, I got 5 rows.

When I set the view format to Chart and choose Pie chart, I got a pie with only 4 sections. I used 'inspect element', and noticed the first row is not included at all in the Google code.

When I went back and added a label to the data element (COUNT ...), the missing fifth row was restored on the chart.

I'd be happy to patch the README.txt to make it more explicit that field labels are required, but I couldn't figure out how to fix this in the code to account for the possibility of a user not checking the box to display a label for the data field.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Thanks for the report. I think ideally we'd just make it so the label wasn't required, or if it is, throw a validation error. It doesn't seem like this is a documentation problem, it's a bug in the implementation.

quicksketch’s picture

Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)

Hmm, I'm having difficulty reproducing this problem. From my inspection of the Views code, it looks as though the label is assigned regardless of whether it is an empty string or not. I couldn't make an item not show up in a pie chart no matter what data input I used, and either through Views or manually assembling chart arrays in the examples file. I'll need some more information on how to reproduce this problem, preferably through an example that can be constructed from a View that doesn't require an excessive amount of contributed modules.

calebtr’s picture

Version: 7.x-2.0-beta5 » 7.x-2.x-dev
Component: Views integration » Google Charts integration
Status: Postponed (maintainer needs more info) » Needs review
FileSize
3.33 KB
855 bytes

Thanks for checking into it. I can't repeat the issue now either, using dev releases for Drupal and Views and Charts 7.x-2.0-rc1.

However, now if I remove the labels I don't see a chart at all.

I'm attaching an exported view that demonstrates the issue; I got the same result if you remove the first row (the labels) from the first example at https://developers.google.com/chart/interactive/docs/gallery/piechart.

It looks like Google Charts API is expecting a string as the data value for the first row in a pie chart. If you remove the label in views, the first row contains an integer.

I'm not sure where the views label is getting unset. It is there (or not) in charts_pre_render_element().

I figured out a way to add an empty string back in as a label if it doesn't exist, for Google pie charts only, but of course this might not be the approach you would take.

calebtr’s picture

Title: first row of results is not included in pie chart if data field has no label » google pie chart does not display if data field has no label

Updating title.

NWOM’s picture

I was having a similar issue, where the charts were not shown. Thanks to this patch, the charts are now showing. Here is an updated patch that fixes a trailing whitespace issue that existed in the previous patch