Make x_axis and y_axis an optional attribute

Created on 27 September 2022, over 2 years ago
Updated 18 January 2023, about 2 years ago

At the moment you need to specify an array for the x_axis and y_axis when using the API (render array type #chart). It would be nice to make them optional.

From the ChartsApiExample.php


    $charts_container['content']['stacked_two_series_column'] = [
      '#type' => 'chart',
      '#tooltips' => $charts_settings->get('charts_default_settings.display.tooltips'),
      '#title' => $this->t('@library Stacked Column Chart (Two Series)', ['@library' => ucfirst($library)]),
      '#chart_type' => 'column',
      'series_one' => $series,
      'series_two' => [
        '#type' => 'chart_data',
        '#title' => $this->t('8.x-3.x'),
        '#data' => [4330, 4413, 4212, 4431],
        '#color' => '#77b259',
      ],
      'x_axis' => $xaxis,
      'y_axis' => $yaxis,
      '#stacking' => TRUE,
      '#raw_options' => [],
    ];

But sometimes you may only use #raw_options. The series attribute is already optional, but if you do not specify x_axis or y_axis you get an error:

The website encountered an unexpected error. Please try again later.
TypeError: array_map(): Argument #2 ($array) must be of type array, null given in array_map() (line 137 of modules/contrib/charts_echarts/src/Plugin/chart/Library/Echarts.php).  
🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇨🇭Switzerland gagarine

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024