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

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).

CommentFileSizeAuthor
Screenshot 2024-10-21 at 9.31.43 AM.png123.14 KBzerbash

Issue fork charts-3482290

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:

  • 3482290- Comparechanges, plain diff MR !112
  • 5.1.x Comparecompare

Comments

zerbash created an issue. See original summary.

andileco made their first commit to this issue’s fork.

andileco’s picture

Status: Active » Needs review

@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?

zerbash’s picture

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';

  • andileco committed 0adad8c2 on 5.1.x
    Issue #3482290 by zerbash, andileco, nikathone: Secondary axis...

andileco’s picture

Status: Needs review » Fixed

Thank you! Automated and manual tests passed for me.

Status: Fixed » Closed (fixed)

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

andileco’s picture

Version: 5.1.x-dev » 5.0.x-dev
noah’s picture

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.

andileco’s picture

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.