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

  1. Create a Views chart display with at least one data provider.
  2. In the chart style settings, configure a grouping field.
  3. Create a chart attachment display, attach it to the primary display, and configure it to use a secondary axis.
  4. Apply the exact same grouping field to the attachment display.
  5. 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

Command icon 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

andileco created an issue. See original summary.

andileco’s picture

Status: Active » Needs review
andileco’s picture

Assigned: andileco » Unassigned
nikathone’s picture

Status: Needs review » Reviewed & tested by the community

  • andileco committed 3ea200cd on 5.2.x
    fix: #3592812 When chart is grouped, chart attachment may fail
    
andileco’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.