Problem/Motivation

I have line chart with four datasets/series. I would like to initially hide the fourth series and only display it when its label is toggled/clicked. I tried all options I could imagine "display", "hidden", "visible", but nothing works. I'm using chrts.js library.
Example of my code:

    $series_four = [
      '#type' => 'chart_data',
      '#title' => 'FR',
      '#data' => array_values($area_data['FR']),
      '#color' => '#ef2670',
      '#hidden' => 'true', // This should hide the series by default, but it can be toggled on in the chart legend.
    ];

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

erwangel created an issue.

andileco’s picture

If your chart is built with Views, you could use the Views Fields On/Off module: https://www.drupal.org/project/views_fields_on_off. Otherwise, I think you will need to write a hook/JS to achieve that.

erwangel’s picture

Unfortunately, my chart is build by code not Views. I'm surprised that this option is not available. In any of the Charts examples we can toggle on/off a dataset but I can not figure out how to set one "off" by default.