Secondary axis overwrites first

Created on 21 October 2024, 2 months ago

If I enable charts_api_example using the chart_chartjs submodule, I get the following example chart:

Based on the data,

      'series_two' => [
        '#type' => 'chart_data',
        '#chart_type' => 'line',
        '#title' => $this->t('8.x-3.x'),
        '#data' => [4330, 4413, 4212, 4431],
        '#color' => '#77b259',
        '#target_axis' => 'y_axis_secondary',
      ],

...the secondary y-axis should be associated with the 4200-4450 scale.

Also, I've now lost the primary y-axis label (Number of Installs).

πŸ› Bug report
Status

Active

Version

5.1

Component

Chart.js integration

Created by

πŸ‡ΊπŸ‡ΈUnited States zerbash

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @zerbash
  • First commit to issue fork.
  • Merge request !112Resolve #3482290 β†’ (Merged) created by andileco
  • πŸ‡ΊπŸ‡ΈUnited States andileco

    @zerbash - apologies, I wasn't seeing your changes when I made my patch. I'm probably fine with either - can you take a look at them and let me know your thoughts?

  • πŸ‡ΊπŸ‡ΈUnited States zerbash

    I don't think checking for ['#opposite'] is the best way to determine a secondary y-axis. That's a valid setting that a user may want to apply to the default y. I think if yAxisID has been set, it's fair to assume that the target is not y:

            $target_axes = array_column($chart_definition['data']['datasets'],'yAxisID');
            $y_axis_key = in_array($child, $target_axes) ? $child : 'y';
  • Pipeline finished with Failed
    2 months ago
    Total: 187s
    #318290
  • Pipeline finished with Failed
    2 months ago
    Total: 583s
    #319658
  • Pipeline finished with Skipped
    about 2 months ago
    #333200
  • πŸ‡ΊπŸ‡ΈUnited States andileco

    Thank you! Automated and manual tests passed for me.

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

  • πŸ‡ΊπŸ‡ΈUnited States andileco
  • πŸ‡¨πŸ‡¦Canada noah

    I have some charts where I'm setting colors via hook_chart_definition_alter(), and the dataset changing from an object to an array here broke that (resulting in a WSOD with β€œError: Attempt to assign property "backgroundColor" on array…”). Fixing it is just a matter of changing, e.g.:

    $definition['data']['datasets'][$delta]->backgroundColor = $color;

    to:

    $definition['data']['datasets'][$delta]['backgroundColor'] = $color;

    …but I figured that was worth documenting here in case anyone else runs into this.

  • πŸ‡ΊπŸ‡ΈUnited States andileco

    Thank you, @noah! I'm really sorry for that inconvenience. I enjoy working with arrays more than objects, so hopefully overall this is a more enjoyable experience.

Production build 0.71.5 2024