Problem/Motivation
When a parent chart and its chart attachment are both grouped in Views, the attachment data fails to render and the secondary axis completely disappears.
This issue stems from how the module handles data mapping for grouped charts. Specifically, inside `ChartsPluginStyleChart::groupedChartElementBuild()`, the `#mapped_data` array is keyed using an integer index ($set_id). However, later in the rendering process, when alignSubChartData() attempts to merge the attachment data into the parent chart, it expects the `#mapped_data` array to be keyed by the actual string labels of the X-axis (e.g., "Jan 2023" or "Male"). Because the keys do not match, the attachment data is nullified, causing the charting library to drop the series and hide the secondary axis.
Steps to reproduce
- Create a Views chart display with at least one data provider.
- In the chart style settings, configure a grouping field.
- Create a chart attachment display, attach it to the primary display, and configure it to use a secondary axis.
- Apply the exact same grouping field to the attachment display.
- Render the view and observe that the attachment series and secondary axis are missing.
Proposed resolution
Update `groupedChartElementBuild()` in `src/Plugin/views/style/ChartsPluginStyleChart.php` to fetch the actual X-axis string label and use it for the `#mapped_data` key, rather than relying on the integer `$set_id`.
Before:
$chart[$element_key]['#mapped_data'][$set_id] = $value;
After:
$mapped_key = $chart['xaxis']['#labels'][$set_id] ?? $set_id;
$chart[$element_key]['#mapped_data'][$mapped_key] = $value;
This ensures that `$child_mapped_data` in `alignSubChartData()` has the correct string keys to successfully match against the parent's string labels.
Remaining tasks
Add tests
User interface changes
None
API changes
None
Data model changes
None
Issue fork charts-3592812
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
andileco commentedComment #4
andileco commentedComment #5
nikathoneComment #7
andileco commented