2amigos/yii2-chartjs-widget

Cannot create Stacked bar

Closed this issue · 2 comments

My code

              `<?= ChartJs::widget([
                         'type' => 'bar',
                             'options' => [
             
                                ],
                'data' => [
                    'labels' => ['2016', '2017', '2018', '2019'],
                    'datasets' => [[
                        'type'=>'bar',
                        'label'=> 'a',
                        'yAxisID'=>"y-axis-0",
                        'backgroundColor' => "rgba(217,83,79,0.75)",
                        'data' => [1000, 2000, 4000, 5000]
                    ],
                    [
                        'type'=>'bar',
                        'label'=> 'b',
                        'yAxisID'=>"y-axis-0",
                        'backgroundColor' => "rgba(92,184,92,0.75)",
                        'data' => [500, 600, 700, 800]
                    ],
                     [
                         'type'=>'line',
                         'fill'=>false,
                         'label'=> 'c',
                         'yAxisID'=>"y-axis-0",
                         'backgroundColor' =>"rgba(51,51,51,0.5)",
    
                         'data' => [150, 200, 400, 500]
                     ],
                    [
                        'type'=>'line',
                        'fill'=>false,
                        'label'=> 'd',
                        'yAxisID'=>"y-axis-1",
                        'backgroundColor' => "rgba(151,187,205,0.5)",
                        'data' => [500, 300, 100, 0]
                    ]]
                ],
                'clientOptions' =>
                [
                    'options' => [
                        'title'=>[
                            'display' => true,
                        ],
                        'tooltips'=>[
                            'mode'=> 'label'
                        ],
                        'responsive'=> true,
                    ],
                    
                    'scales'=> [
                        'xAxes'=> [
                            'stacked'=>true,
                        ],
                        'yAxes'=>[
                             [
                                'stacked'=>true,
                                'position'=>'left',
                                'id'=> "y-axis-0",
                             ],
                             [
                                'stacked'=>false,
                                'position'=>'right',
                                'id'=> "y-axis-1",
                             ],

                        ]
                    ],
                ],
            ]);
        ?>`

Worked after

changing
'xAxes'=> [ 'stacked'=>true, ],

into

'xAxes'=> [ [ 'stacked'=>true,] ],