Search code examples
javascriptyii2apexcharts

Yii2 is it possible to toggle onmotion/yii2-widget-apexcharts series by default?


I am using onmotion/yii2-widget-apexcharts. In my chart I have series with ~ 20 data sets but I don't want show them all after page loads (like it's toggled off), instead it would be nice if chart could show only selected series names with option toggle those who are hidden. Primary need is to toggle all series off when page loads, perfect need is toggle off selected series. Can anyone help me with this?


Solution

  • You can disable specific series_name by adding JS code to the widget initialization. id is generated, so it can help to specify it explicitly.

    <?= ApexchartsWidget::widget([
        ...merge your existing code...,
        'chartOptions' => [
            'chart' => [
                'id' => 'your_chart_id',
            ],
        ],
        'js' => new JsExpression("ApexCharts.exec('your_chart_id', 'hideSeries', 'series_name')"),
    ]); ?>